# System.Double question

**URL:** <https://www.ruby-forum.com/t/system-double-question/125566>\
**Category:** IronRuby\
**Created:** [January 10, 2008, 9:01am UTC](https://www.ruby-forum.com/t/system-double-question/125566 "2008-01-10T09:01:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [January 10, 2008, 9:01am UTC](https://www.ruby-forum.com/t/system-double-question/125566/1 "2008-01-10T09:01:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [January 10, 2008, 4:07pm UTC](https://www.ruby-forum.com/t/system-double-question/125566/2 "2008-01-10T16:07:38Z")

</div>

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: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Peter Bacon  
Darwin  
Sent: Thursday, January 10, 2008 12:01 AM  
To: removed\_email\_address@domain.invalid  
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
