[Issue 10215] New: const causes false float calculation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 30 12:38:48 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10215

           Summary: const causes false float calculation
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: rswhite4 at googlemail.com


--- Comment #0 from rswhite4 at googlemail.com 2013-05-30 12:38:47 PDT ---
Example #1:
----
import std.stdio;

class Foo {
public:
    float a = 3.14 / 2 / 0.5;
    const float b = 3.14 / 2 / 0.5;
}

void main()
{
    float a = 3.14 / 2 / 0.5;
    const float b = 3.14 / 2 / 0.5;

    writefln("a = %f, b = %f", a, b);

    Foo f = new Foo();
    writefln("a = %f, b = %f", f.a, f.b);
}
----
Expected:
a = 3.140000, b = 3.140000
a = 3.140000, b = 3.140000

I get:
a = 3.140000, b = 3.140000
a = 3.140000, b = 0.000000

Example #2:
----
import std.math;
import std.stdio;

class Foo {
public:
    const float airTime = 0.5;

    //Speed to progress the jump
    const float jumpSinWaveSpeed = PI_2 / airTime;
    float jumpSinWaveSpeed2 = PI_2 / airTime;
}

void main() {
    Foo f = new Foo();
    writeln(f.jumpSinWaveSpeed);
    writeln(f.jumpSinWaveSpeed2);
}
----

Expected:
3.14159
3.14159

I get:
6.39384e-39
3.14159

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list