# Math::Infinity and Math::NaN

**URL:** <https://rubytalk.org/t/math-infinity-and-math-nan/17993>\
**Category:** ruby-talk\
**Created:** [29 April 2005 04:44 UTC](https://rubytalk.org/t/math-infinity-and-math-nan/17993 "2005-04-29T04:44:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [29 April 2005 04:44 UTC](https://rubytalk.org/t/math-infinity-and-math-nan/17993/1 "2005-04-29T04:44:27Z")

</div>

I think it'd be useful to define Infinity and NaN as constants (perhaps  
within Math, if they'd "pollute" the top level). The way I see it,  
there's no real reason not to, and right now one has to resort to clumsy  
looking workarounds to get at them.

martin

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [29 April 2005 05:04 UTC](https://rubytalk.org/t/math-infinity-and-math-nan/17993/2 "2005-04-29T05:04:28Z")

</div>

Hi Martin,

&nbsp;&nbsp;The new version of Facets (0.7) has an Infinity class. Of course due  
to it's add-on nature it isn't fully integrated into the rest of the  
Ruby class system (yet) we're working on it. I will consider also a NaN  
class.

Thanks,  
T.

---

<div class="post-metadata">

**Author:** ![Mark\_Hubbart1](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Mark\_Hubbart1](https://rubytalk.org/u/Mark_Hubbart1)\
**Post date:** [29 April 2005 05:48 UTC](https://rubytalk.org/t/math-infinity-and-math-nan/17993/3 "2005-04-29T05:48:25Z")

</div>

This has been talked about a few times before on the list... I think I  
remember it being suggested that there might not be a portable way to  
generate Infinity and NaN on every platform.

cheers,  
Mark

> **···**
>
> On 4/28/05, Martin DeMello \<martindemello@yahoo.com\> wrote:
> 
> > I think it'd be useful to define Infinity and NaN as constants (perhaps  
> > within Math, if they'd "pollute" the top level). The way I see it,  
> > there's no real reason not to, and right now one has to resort to clumsy  
> > looking workarounds to get at them.

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [29 April 2005 05:19 UTC](https://rubytalk.org/t/math-infinity-and-math-nan/17993/4 "2005-04-29T05:19:28Z")

</div>

Why classes? They're simply constants of type Float (defined in the IEEE  
standard), and ruby already does provide access to them, complete with  
pretty printing. It's just that it's a bit roundabout - e.g. you have to  
say a = 1.0/0 rather than a = Infinity.

martin

> **···**
>
> Trans \<transfire@gmail.com\> wrote:
> 
> > Hi Martin,
> > 
> > &nbsp;&nbsp;The new version of Facets (0.7) has an Infinity class. Of course due  
> > to it's add-on nature it isn't fully integrated into the rest of the  
> > Ruby class system (yet) we're working on it. I will consider also a NaN  
> > class.

---

<div class="post-metadata">

**Author:** ![Florian\_Gross2](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@Florian\_Gross2](https://rubytalk.org/u/Florian_Gross2)\
**Post date:** [29 April 2005 12:03 UTC](https://rubytalk.org/t/math-infinity-and-math-nan/17993/5 "2005-04-29T12:03:44Z")

</div>

Martin DeMello wrote:

> Why classes? They're simply constants of type Float (defined in the IEEE  
> standard), and ruby already does provide access to them, complete with  
> pretty printing. It's just that it's a bit roundabout - e.g. you have to  
> say a = 1.0/0 rather than a = Infinity.

Having them implemented in a custom way would let you use them portably. (Negative) infinity is quite useful when working with Ranges even if it does not consider itself equal to 1.0 / 0.0.
