floating-accuracy

Why does 99.99 / 100 = 0.9998999999999999

Possible Duplicate: Dealing with accuracy problems in floating-point numbers Whereas 99.99 * 0.01 = 0.99 Clearly this is the age old floating point rounding issue, however the rounding error in this case seems quite large to me; what I mean is I might have expected a result of 0.99990000001 or some similar 'close' result. An...

Fixing Floating Point Error

I have some code that gets the leading value (non-zero) of a Double using normal math instead of String Math... For Example: 0.020 would return 2 3.12 would return 3 1000 should return 1 The code I have at the moment is: LeadingValue := Trunc(ResultValue * Power(10, -(Floor(Log10(ResultValue))))) However when ResultValue is 1000 the...

0.699 x 100 = 69.89999999999999 ?

Possible Duplicates: Why does 99.99 / 100 = 0.9998999999999999 Dealing with accuracy problems in floating-point numbers I've seen this issue in php and javascript. I have this number: float 0.699 if I do this: 0.699 x 100 = 69.89999999999999 why? edit round(0.699 x 10, 2): float 69.90000000000001 ...

python floating number

i am kind of confused why python add some additional decimal number in this case, please help to explain >>> mylist = ["list item 1", 2, 3.14] >>> print mylist ['list item 1', 2, 3.1400000000000001] ...

Why can't I multiply a float?

Possible Duplicate: Dealing with accuracy problems in floating-point numbers I was quite surprised why I tried to multiply a float in C (with GCC 3.2) and that it did not do as I expected.. As a sample: int main() { float nb = 3.11f; nb *= 10; printf("%f\n", nb); } Displays: 31.099998 I am curious regarding the way f...

strange results with /fp:fast

We have some code that looks like this: inline int calc_something(double x) { if (x > 0.0) { // do something return 1; } else { // do something else return 0; } } Unfortunately, when using the flag /fp:fast, we get calc_something(0)==1 so we are clearly taking the wrong code path. This only happens when we use th...

Dividing a double with integer

I am facing an issue while dividing a double with an int. Code snippet is : double db = 10; int fac = 100; double res = db / fac; The value of res is 0.10000000000000001 instead of 0.10. Does anyone know what is the reason for this? I am using cc to compile the code. ...

Is there a bignum library for JavaScript?

Is there a bignum library for JavaScript that I can include like <script type="text/javascript" src="the_bignum_library.js"></script> ? I think my users would prefer to enter numbers in a web page and wait a 7 seconds for a result, rather than download an executable and click through a bunch of "this executable could possibly harm yo...

How to get around some rounding errors?

I have a method that deals with some geographic coordinates in .NET, and I have a struct that stores a coordinate pair such that if 256 is passed in for one of the coordinates, it becomes 0. However, in one particular instance a value of approximately 255.99999998 is calculated, and thus stored in the struct. When it's printed in ToStrin...

Is there an exact equivalent for the .NET Double type in SQL Server?

Possible Duplicate: What represents a double in sql server? Is there an exact equivalent for the .NET Double type in SQL Server? Failing that, is there one which gives a good approximation? EDIT: It looks like this link gives the most definitive answer: Mapping CLR Parameter Data ...

Taking Logarithms of relatively small numbers in different languages/architectures/operating systems

In Java I run: System.out.println(Math.log(249.0/251.0)); Output: -0.008000042667076265 In C# I run: <- fixed Math.Log (x/y); \\where x, y are almost assuredly 249.0 and 251.0 respectively Output: -0.175281838 (printed out later in the program) Google claims: Log(249.0/251.0) Output: -0.00347437439 And MacOS claim...

How does the decimal accuracy of Python compare to that of C?

I was looking at the Golden Ratio formula for finding the nth Fibonacci number, and it made me curious. I know Python handles arbitrarily large integers, but what sort of precision do you get with decimals? Is it just straight on top of a C double or something, or does it use a a more accurate modified implementation too? (Obviously not...

Detecting precision loss when converting from double to float

I am writing a piece of code in which i have to convert from double to float values. I am using boost::numeric_cast to do this conversion which will alert me of any overflow/underflow. However i am also interested in knowing if that conversion resulted in some precision loss or not. For example double source = 1988.1012; floa...

SQLite query where clause with floating point numbers fails?

I'm putting a float in an Android based SQLite database, like so: private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " (" + KEY_ID + " integer primary key autoincrement, " + KEY_FLOAT + " REAL, " + ... ... content.put(KEY_FLOAT, 37.3f); db.insert(DATABASE_TAB...

My variance function in C# does not return accurate value

The source data : static double[] felix = new double[] { 0.003027523, 0.002012256, -0.001369238, -0.001737660, -0.001647287, 0.000275154, 0.002017238, 0.001372621, 0.000274148, -0.000913576, 0.001920263, 0.001186456, -0.000364631, 0.000638337, 0.000182266, -0.001275626, -0.000821093, 0.001186998, -0.000455996, -0.0...

Does Fortran have inherent limitations on numerical accuracy compared to other languages?

While working on a simple programming exercise, I produced a while loop (DO loop in Fortran) that was meant to exit when a real variable had reached a precise value. I noticed that due to the precision being used, the equality was never met and the loop became infinite. This is, of course, not unheard of and one is advised that, rather ...

Perl modulo operator question

Why does the first example print a wrong result ? perl -le 'print $x = 100*1.15 % 5' 4 perl -le 'print $x = 1000*1.15 % 5' 0 ...

Floating point C++ compiler options | preventing a/b -> a* (1/b)

I'm writing realtime numeric software, in C++, currently compiling it with Visual-C++ 2008. Now using 'fast' floating point model (/fp:fast), various optimizations, most of them useful my case, but specifically: a/b -> a*(1/b) Division by multiplicative inverse is too numerically unstable for a-lot of my calculations. (see: Microsoft...

Objective C Math Formula Fail

Hi, noob here wants to calculate compound interest on iPhone. float principal; float rate; int compoundPerYear; int years; float amount; formula should be: amount = principal*(1+rate/compoundPerYear)^(rate*years) I get slightly incorrect answer with: amount = principal*pow((1+(rate/compoundPerYear)), (compoundPerYear*years)); I'm...

Handling Massive (high precision) Floats in Ruby

I'm making an application which is listening to prices being updated regularly, but occasionally my data source throws me something like "1.79769313486232e+308". The numbers that get sent will never by really big numbers (eg. "179769313486232e+308"), but as with the example above, they come with a lot of precision. I'd be happy to drop ...