System.Double question

I added this to the FloatOps class:

    [RubyConstant]

    public const double MAX = double.MaxValue;

But this generated the following code in InitializerGenerated.cs:

    def11.SetConstant("MAX", 1.79769313486232E+308);

This won’t compile.

The compiler says that this number is too large for a double.
Double.MaxValue is actually 1.7976931348623157E+308.

The initializer generator code calls ToString on the value of the
constant
to generate the SetConstant line of code. Unfortunately this only
outputs
15 significant figures, causing the number to be rounded up to
1.79769313486232E+308, which of course is larger than double.MaxValue.

Any good ideas on how to work around this?

Cheers,

Pete

I fixed this on our side and will go out in the next push to SVN.

The fix was easy - rather than emitting the constant value, we emit a
reference to the constant:

def11.SetConstant(“MAX”, FloatOps.MAX);

Thanks,
-John

From: [email protected]
[mailto:[email protected]] On Behalf Of Peter Bacon
Darwin
Sent: Thursday, January 10, 2008 12:01 AM
To: [email protected]
Subject: [Ironruby-core] System.Double question

I added this to the FloatOps class:

    [RubyConstant]
    public const double MAX = double.MaxValue;

But this generated the following code in InitializerGenerated.cs:

    def11.SetConstant("MAX", 1.79769313486232E+308);

This won’t compile.

The compiler says that this number is too large for a double.
Double.MaxValue is actually 1.7976931348623157E+308.
The initializer generator code calls ToString on the value of the
constant to generate the SetConstant line of code. Unfortunately this
only outputs 15 significant figures, causing the number to be rounded up
to 1.79769313486232E+308, which of course is larger than
double.MaxValue.

Any good ideas on how to work around this?

Cheers,
Pete