# How to query FLT\_MAX from Ruby code?

**URL:** https://rubytalk.org/t/how-to-query-flt-max-from-ruby-code/3740
**Category:** ruby-talk
**Created:** [21 December 2002 01:17 UTC](https://rubytalk.org/t/how-to-query-flt-max-from-ruby-code/3740 "2002-12-21T01:17:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Lyle\_Johnson6](https://avatars.discourse-cdn.com/v4/letter/l/bb73d2/32.png) [@Lyle\_Johnson6](https://rubytalk.org/u/Lyle_Johnson6)
#### Post date: [21 December 2002 01:17 UTC](https://rubytalk.org/t/how-to-query-flt-max-from-ruby-code/3740/1 "2002-12-21T01:17:20Z")

</div>

I hope I’m not setting myself up for a Doh! moment…

Is there some way to determine (from Ruby code) the minimum and maximum  
limits for Ruby Floats (i.e. along the lines of the C constants FLT\_MIN,  
FLT\_MAX, DBL\_MIN and DBL\_MAX from the \<limits.h\> header file)?

---

<div class="post-metadata">

### Author: ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)
#### Post date: [21 December 2002 03:57 UTC](https://rubytalk.org/t/how-to-query-flt-max-from-ruby-code/3740/2 "2002-12-21T03:57:39Z")

</div>

> I hope I’m not setting myself up for a Doh! moment…
> 
> Is there some way to determine (from Ruby code) the minimum and maximum  
> limits for Ruby Floats (i.e. along the lines of the C constants FLT\_MIN,  
> FLT\_MAX, DBL\_MIN and DBL\_MAX from the \<limits.h\> header file)?

Beats me. But if there’s not, maybe there should be.  
Time for an RCR? Something like Float::FLT\_MAX etc.?

Hal

> **···**
>
> ----- Original Message -----  
> From: “Lyle Johnson” [lyle@users.sourceforge.net](mailto:lyle@users.sourceforge.net)  
> Newsgroups: comp.lang.ruby  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Friday, December 20, 2002 7:17 PM  
> Subject: How to query FLT\_MAX from Ruby code?

---

<div class="post-metadata">

### Author: ![Bil\_Kleb2](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@Bil\_Kleb2](https://rubytalk.org/u/Bil_Kleb2)
#### Post date: [22 December 2002 02:01 UTC](https://rubytalk.org/t/how-to-query-flt-max-from-ruby-code/3740/3 "2002-12-22T02:01:54Z")

</div>

Hal E. Fulton wrote:

> > Lyle Johnson wrote:
> > 
> > Is there some way to determine (from Ruby code) the minimum and maximum  
> > limits for Ruby Floats (i.e. along the lines of the C constants FLT\_MIN,  
> > FLT\_MAX, DBL\_MIN and DBL\_MAX from the \<limits.h\> header file)?
> 
> Beats me. But if there’s not, maybe there should be.  
> Time for an RCR? Something like Float::FLT\_MAX etc.?

Dave sat with me a few years ago and helped me enter an RCR for this. I haven’t  
checked it’s status in a year or so. For the time being we apply our own patch  
whenever we install ruby. (Included after signature.)

> **···**
>
> –  
> Bil Kleb  
> NASA Langley Research Center  
> Hampton, Virginia, USA
> 
> \*\*\* numeric.c 2002/03/12 05:29:13 1.1  
> — numeric.c 2002/03/18 12:55:24
> 
> * * *
> 
> \*\*\* 13,18 \*\*\*\*  
> — 13,21 ----  
> #include “ruby.h”  
> #include \<math.h\>  
> #include \<stdio.h\>
> 
> - #ifdef HAVE\_FLOAT\_H
> - #include \<float.h\>
> - #endif  
> #if defined( **FreeBSD** ) && **FreeBSD** \< 4  
> #include \<floatingpoint.h\>  
> #endif
> 
> * * *
> 
> \*\*\* 1646,1651 \*\*\*\*  
> — 1649,1668 ----  
> rb\_define\_singleton\_method(rb\_cFloat, “induced\_from”, rb\_flo\_induced\_from, 1);  
> rb\_include\_module(rb\_cFloat, rb\_mPrecision);
> 
> - #ifdef HAVE\_FLOAT\_H
> - 
> 
> ```
> rb_define_const(rb_cFloat, "ROUNDS", INT2FIX(FLT_ROUNDS));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "RADIX", INT2FIX(FLT_RADIX));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "MANT_DIG", INT2FIX(DBL_MANT_DIG));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "DIG", INT2FIX(DBL_DIG));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "MIN_EXP", INT2FIX(DBL_MIN_EXP));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "MAX_EXP", INT2FIX(DBL_MAX_EXP));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "MIN_10_EXP", INT2FIX(DBL_MIN_10_EXP));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "MAX_10_EXP", INT2FIX(DBL_MAX_10_EXP));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "MIN", rb_float_new(DBL_MIN));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "MAX", rb_float_new(DBL_MAX));
> 
> ```
> 
> - 
> 
> ```
> rb_define_const(rb_cFloat, "EPSILON", rb_float_new(DBL_EPSILON));
> 
> ```
> 
> - #endif
> - 
> 
> ```
> rb_define_method(rb_cFloat, "to_s", flo_to_s, 0);
> rb_define_method(rb_cFloat, "coerce", flo_coerce, 1);
> rb_define_method(rb_cFloat, "-@", flo_uminus, 0);
> 
> ```
> 
> \*\*\* configure.in 2002/03/18 12:52:21 1.1  
> — configure.in 2002/03/18 12:52:26
> 
> * * *
> 
> \*\*\* 256,262 \*\*\*\*  
> AC\_HEADER\_DIRENT  
> AC\_HEADER\_STDC  
> AC\_HEADER\_SYS\_WAIT  
> ! AC\_CHECK\_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h  
> fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h  
> syscall.h pwd.h a.out.h utime.h memory.h direct.h sys/resource.h)
> 
> — 256,262 ----  
> AC\_HEADER\_DIRENT  
> AC\_HEADER\_STDC  
> AC\_HEADER\_SYS\_WAIT  
> ! AC\_CHECK\_HEADERS(stdlib.h string.h unistd.h limits.h float.h sys/file.h sys/ioctl.h  
> fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h  
> syscall.h pwd.h a.out.h utime.h memory.h direct.h sys/resource.h)

---

<div class="post-metadata">

### Author: ![Lyle\_Johnson4](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Lyle\_Johnson4](https://rubytalk.org/u/Lyle_Johnson4)
#### Post date: [22 December 2002 14:49 UTC](https://rubytalk.org/t/how-to-query-flt-max-from-ruby-code/3740/4 "2002-12-22T14:49:42Z")

</div>

Bil Kleb wrote:

> Dave sat with me a few years ago and helped me enter an RCR for this.

OK, found it here:

```
http://www.rubygarden.org/article.php?sid=103

```

Date is September 21 (not sure of which year).

> I haven’t checked its status in a year or so.

Looks like it’s stuck in RCR limbo, neither accepted nor rejected. I  
just added my vote 😉
