Questions tagged [numeric]

This tag is for questions concerning problems using numbers which either cannot be exactly solved, or where the exact solution may be much more difficult to acquire than by using numerical methods.

This tag is for questions concerning problems using numbers which either cannot be exactly solved, or where the exact solution may be much more difficult to acquire than by using numerical methods.

It includes questions about algorithms, precision and accuracy of underlying numbers, advantages and disadvantages of several methods, error propagation, problems with the underlying numbers and data structures.

2593 questions
10
votes
3 answers

PostgreSQL adds trailing zeros to numeric

Recently I migrated a DB to PostgreSQL that has some columns defined as numeric(9,3) and numeric(9,4). In testing the app I have found that when data is saved to these columns there are trailing zeros being added to the value inserted. I am using…
verbyk1924
  • 221
  • 1
  • 2
  • 8
10
votes
4 answers

Value of real type incorrectly compares

I have field of REAL type in db. I use PostgreSQL. And the query SELECT * FROM my_table WHERE my_field = 0.15 does not return rows in which the value of my_field is 0.15. But for instance the query SELECT * FROM my_table WHERE my_field >…
Mike Brown
  • 201
  • 3
  • 11
10
votes
2 answers

why (0+0i)^{0} == (nan, nan) in c++

take a look at the code blew: #include #include int main() { std::cout << std::pow( std::complex(0,0), std::complex(0,0) ) << "\n"; std::cout << std::pow( std::complex(0,0), double(0) ) <<…
Feng Wang
  • 1,506
  • 15
  • 17
10
votes
2 answers

Validation in textbox in WPF

I am currently working on a WPF application where I would like to have a TextBox that can only have numeric entries in it. I know that I can validate the content of it when I lost the focus and block the content from being numeric, but in other…
David Brunelle
  • 6,528
  • 11
  • 64
  • 104
10
votes
2 answers

How to convert a base 10 number to alphabetic like ordered list in HTML

I want to convert a integer to alphabetic equivalent like ordered list in HTML.
    I tried to convert a base 10 number to a base 26 with a-z digits. But that's not what I wanted. IN WANT GET ----------------------- 1 …
oliholz
  • 7,447
  • 2
  • 43
  • 82
9
votes
4 answers

javascript (jquery) numeric input: keyCode for '3' and '#' are the same

I need to set up an so that it will accept only numeric chars, backspace, delete, enter, tabs and arrows. There's a lot of exemple around there, i started with something similar to this: function isNumericKeyCode (keyCode){ …
Johnny5
  • 6,664
  • 3
  • 45
  • 78
9
votes
7 answers

is_numeric, intval, ctype__digit.. can you rely on them?

is_numeric, intval, ctype__digit.. can you rely on them? or do i have to use regex? function isNum($str) { return (preg_match("/^[0-9]+$/", $str)); } what do you guys think? am i stupid?
Mutabu
9
votes
1 answer

Detecting specialization of std::numeric::type for some non numeric type T

I want to check to see if a type has an entry in std::numeric_limits. When the type is an array - (or perhaps not a number?) I get a compiler error. This prevents me from detecting and branching based on whether the type is supported in…
Robert Ramey
  • 1,114
  • 8
  • 16
9
votes
5 answers

Dot product of two lists in Python

I need to write the function dot( L, K ) that should output the dot product of the lists L and K. If these two input lists are not of equal length, dot should output 0. If these two lists are both empty, dot also should output 0. You should assume…
Benjamin Brooks
  • 195
  • 3
  • 6
  • 14
9
votes
1 answer

Numerically stable evaluation of sqrt(x+a) - sqrt(x)

Is there an elegant way of numerically stable evaluating the following expression for the full parameter range x,a >= 0? f(x,a) = sqrt(x+a) - sqrt(x) Also is there any programming language or library that does provide this kind of function? If yes,…
Andreas H.
  • 5,557
  • 23
  • 32
9
votes
2 answers

How to set up implicit conversion to allow arithmetic between numeric types?

I'd like to implement a class C to store values of various numeric types, as well as boolean. Furthermore, I'd like to be able to operate on instances of this class, between types, converting where necessary Int --> Double and Boolean -> Int, i.e.,…
ostolop
  • 163
  • 5
9
votes
3 answers

Fast implementation/approximation of pow() function in C/C++

I m looking for a faster implementation or good a approximation of functions provided by cmath. I need to speed up the following functions pow(x,y) exp(z*pow(x,y)) where z<0. x is from (-1.0,1.0) and y is from (0.0, 5.0)
zoli2k
  • 3,388
  • 4
  • 26
  • 36
9
votes
1 answer

How to Convert Numeric Data into Currency in R?

Searched Google and SO and couldn't find a good answer. I have the following table: Country Value 23 Bolivia 2575.684 71 Guyana 3584.693 125 Paraguay 3878.150 49 Ecuador 5647.638 126 Peru 6825.461 38 Colombia …
cavaunpeu
  • 614
  • 1
  • 6
  • 16
9
votes
2 answers

JVM Arbitrary Precision Libraries

I'm working on a project ( in Scala ), where I have a need to manipulate some very large numbers; far too big to be represented by the integral types. Java provides the BigInteger and BigDecimal classes (and scala provides a nice thin wrapper…
nomad
  • 1,809
  • 2
  • 18
  • 33
8
votes
1 answer

Scala Generics and Numeric Implicits

I need to pass two functions as parameters to a scala function. That function should then evaluate them and get a number from them where it will then operate on. This number can be either a Int, Double or any other numeric type. I would like the…
tiagoboldt
  • 2,426
  • 1
  • 24
  • 30