Re: Calculation differences between Debug and Release mode

2013-04-28 Thread Marco Leise
Am Mon, 15 Apr 2013 11:51:43 -0400 schrieb Steven Schveighoffer schvei...@yahoo.com: On Mon, 15 Apr 2013 11:51:07 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: I would suspect that the issue is floating point error. On certain hardware, the CPU uses higher-precision 80-bit

Re: Calculation differences between Debug and Release mode

2013-04-28 Thread Ali Çehreli
On 04/28/2013 12:39 PM, Marco Leise wrote: What worries me is that this jeopardizes the efforts put into C to make floating point calculations the same under all circumstances. That is news to me. I remember knowing this problem from C. Perhaps something new in the C standard that I haven't

Re: Calculation differences between Debug and Release mode

2013-04-20 Thread Simen Kjaeraas
On Sat, 13 Apr 2013 18:36:21 +0200, Jeremy DeHaan dehaan.jerem...@gmail.com wrote: I'm on Windows, and I my compilation was nothing more than dmd -O -release main.d to get the issue I described. Turns out, the problem starts here: static const(float) pi = 3.141592654f; If we compare

Re: Calculation differences between Debug and Release mode

2013-04-20 Thread Ali Çehreli
Thanks for the analysis. On 04/20/2013 05:30 AM, Simen Kjaeraas wrote: static const(float) pi = 3.141592654f; If we compare that to std.math.PI, we see that they're different: writeln( 3.141592654f - std.math.PI ); 4.10207e-10 std.math.PI is a 'real'. According to the

Re: Calculation differences between Debug and Release mode

2013-04-20 Thread Casper Færgemand
The D book has a diagram that shows implicit conversions. All implicit conversions from integral types to floating point go to real, not double or float.

Re: Calculation differences between Debug and Release mode

2013-04-20 Thread Ali Çehreli
On 04/20/2013 11:04 AM, Casper Færgemand shortt...@gmail.com wrote: The D book has a diagram that shows implicit conversions. It is Figure 2.3 on page 44 of my copy of TDPL. All implicit conversions from integral types to floating point go to real, not double or float. Yes. The figure

Re: Calculation differences between Debug and Release mode

2013-04-15 Thread Steven Schveighoffer
On Mon, 15 Apr 2013 11:51:07 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: I would suspect that the issue is floating point error. On certain hardware, the CPU uses higher-precision 80-bit floating points. When you store those back to doubles, the extra precision is truncated.

Re: Calculation differences between Debug and Release mode

2013-04-15 Thread Steven Schveighoffer
On Sat, 13 Apr 2013 02:07:39 -0400, Jeremy DeHaan dehaan.jerem...@gmail.com wrote: I have a function that will calculate a random point on a circle based on a specified radius and total number of points. The only point in question is the first point. I get different values when the code

Calculation differences between Debug and Release mode

2013-04-13 Thread Jeremy DeHaan
I have a function that will calculate a random point on a circle based on a specified radius and total number of points. The only point in question is the first point. I get different values when the code compiles in Release and Debug mode. Here is some code: Vector2f getPoint(uint index) {

Re: Calculation differences between Debug and Release mode

2013-04-13 Thread Alexandr Druzhinin
I'm not sure, but I suspect this is because of 80-bit intermediary float point operation result. Its precision too excessive and gives us this inexpectible result. But when you use an intermediary variable this exessive intermediary result is rounded properly and you get what you expect. See

Re: Calculation differences between Debug and Release mode

2013-04-13 Thread Simen Kjaeraas
On Sat, 13 Apr 2013 08:07:39 +0200, Jeremy DeHaan dehaan.jerem...@gmail.com wrote: In debug mode this works as expected. Let's say the radius is 50. getPoint(0) returns a vector that prints X: 50 Y: 0. For some reason, the same function will return a vector that prints X: 50 Y:

Re: Calculation differences between Debug and Release mode

2013-04-13 Thread Jeremy DeHaan
On Saturday, 13 April 2013 at 11:59:12 UTC, Simen Kjaeraas wrote: On Sat, 13 Apr 2013 08:07:39 +0200, Jeremy DeHaan dehaan.jerem...@gmail.com wrote: In debug mode this works as expected. Let's say the radius is 50. getPoint(0) returns a vector that prints X: 50 Y: 0. For some reason, the