floating-accuracy

SQL server 2005 numeric precision loss

Hello, Debugging some finance-related SQL code found a strange issue with numeric(24,8) mathematics precision. Running the following query on your MSSQL you would get A + B * C expression result to be 0.123457 SELECT A, B, C, A + B * C FROM ( SELECT CAST(0.12345678 AS NUMERIC(24,8)) AS A, CAST(0 AS NUMERIC(...

What is a simple example of floating point/rounding error?

I've heard of "error" when using floating point variables. Now I'm trying to solve this puzzle and I think I'm getting some rounding/floating point error. So I'm finally going to figure out the basics of floating point error. What is a simple example of floating point/rounding error (preferably in C++) ? Edit: For example say I have...

python - decimal place issues with floats

I seem to be losing a lot of precision with floats. For example I need to solve a matrix: 4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 this is the code i use to import the matrix from a text file: f = open('gauss.dat') lines = f.readlines() f.close() j=0 for line in lines: bits = string.split(line, ',') ...

Floating Point Limitations

My code: a = '2.3' I wanted to display a as a floating point value. Since a is a string, I tried: float(a) The result I got was : 2.2999999999999998 I want a solution for this problem. Please, kindly help me. I was following this tutorial. ...

PI and accuracy of a floating point number

A single/double/extended precision floating point representation of Pi is accurate up to how many decimal places? ...

Is JavaScript's Math broken?

0.1 + 0.2 == 0.3 // returns false 0.1 + 0.2 // returns 0.30000000000000004 Any ideas why this happens? ...

Dealing with accuracy problems in floating-point numbers

I was wondering if there is a way of overcoming an accuracy problem that seems to be the result of my machine's internal representation of floating-point numbers: For the sake of clarity the problem is summarized as: // str is "4.600"; atof( str ) is 4.5999999999999996 double mw = atof( str ) // The variables used in the columns...

Why the result is different for this problem?

I came across this following arithmetic problem. But the result is different from normal maths operation, Why is it so? double d1 = 1.000001; double d2 = 0.000001; Console.WriteLine((d1-d2)==1.0); ...

php intval() and floor() return value that is too low?

Because the float data type in PHP is inaccurate, and a FLOAT in MySQL takes up more space than an INT (and is inaccurate), I always store prices as INTs, multipling by 100 before storing to ensure we have exactly 2 decimal places of precision. However I believe PHP is misbehaving. Example code: echo "<pre>"; $price = "1.15"; echo "Pri...

How to determine the accuracy of Pi (π)

Optimizing a game we're developing, we're running into the phase where every CPU cycle won counts. We using radians for position calculations of objects circling around other objects and I want to cut the needless accuracy in my lookup tables. For that, we make heavy use of a predefined Pi. How accurate should this Pi be? So, my questio...

How can I work around a round-off error that causes an infinite loop in Perl's Statistics::Descriptive?

I'm using the Statistics::Descriptive library in Perl to calculate frequency distributions and coming up against a floating point rounding error problem. I pass in two values, 0.205 and 0.205, (taken from other numbers and sprintf'd to those) to the stats module and ask it to calculate the frequency distribution but it's getting stuck i...

Rounding Errors?

In my course, I am told: Continuous values are represented approximately in a memory, and therefore computing with floats involves rounding errors. These are tiny discrepancies in bit patterns; thus the test e==f is unsafe if e and f are floats. Referring to Java. Is this true? I've used comparison statements with doub...

1.265 * 10000 = 126499.99999999999 ?????

How come when I multiply 1.265 by 10000 I Get this 126499.99999999999 when using Javascript ...

How to do an integer log2() in C++?

In the C++ standard libraries I found only a floating point log method. Now I use log to find the level of an index in a binary tree ( floor(2log(index)) ). Code (C++): int targetlevel = int(log(index)/log(2)); I am afraid that for some of the edge elements (the elements with value 2^n) log will return n-1.999999999999 instead of n....

How are mathematical libraries with infinite precision implemented?

So I know about floating point precision (and how things like 1.1 can't be expressed exactly in binary) and all that, but I'm wondering: how then, do math-related libraries implement infinite precision? In other words, how would you represent, for example, 1.1 accurately in binary? Just a brief description would be great, I can figure ou...

PHP/MySQL: Best money operations/storing practices??

Hi all! First of all sorry for my English, it's not my native language. So, I am planning to make an application (PHP/MySQL) which deals a lot with money, and I am thinking about how to store and operate with the money, referring to PHP float data type and MySQL decimal. I was thinking of two options. One of them is to operate and st...

What's wrong with using == to compare floats in Java?

According to this java.sun page == is the equality comparison operator for floating point numbers in Java. However, when I type this code: if(sectionID == currentSectionID) into my editor and run static analysis, I get: "JAVA0078 Floating point values compared with ==" What is wrong with using == to compare floating point...

[.net] Floating point equivalence?

I want to be able to compare two doubles disregarding a possible precision loss. Is there a method already that handles this case? If not, is there a threshold/guideline to know how much is an adequate equivalence between two doubles? ...

Latitude/Longitude storage and compression in C

Does anyone know the most efficient representation for lat/long coordinates? Accuracy level should be enough for consumer GPS devices. Most implementations seem to use double for each unit, but I'm suspicious that a float or fixed point format should be sufficient. I'd be curious to hear from anyone who has tried to compress and or stor...

For-loop in C++ using double breaking out one step early, boundary value not reached

I have a simple C++ program compiled using gcc 4.2.4 on 32-bit Ubuntu 8.04. It has a for-loop in which a double variable is incremented from zero to one with a certain step size. When the step size is 0.1, the behavior is what I expected. But when the step size is '0.05', the loop exits after 0.95. Can anyone tell me why this is happenin...