From: Bil Kleb Date: 2002-12-22T11:01:54+09:00 Subject: Re: How to query FLT_MAX from Ruby code? 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 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 #include + #ifdef HAVE_FLOAT_H + #include + #endif #if defined(__FreeBSD__) && __FreeBSD__ < 4 #include #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)