From: Bil Kleb Date: 2002-02-01T09:34:15+09:00 Subject: Re: smallest non-zero number (and other limits) It looks like it has been a year since I first posed this question [ruby-talk:9948]. Our current answer is to run the following c-program on for each machine we use: #include #include #include int main(){ FILE *rubyFloat = fopen("Float.rb","w"); fprintf(rubyFloat,"class Float\n"); fprintf(rubyFloat," FLT_EPSILON = %.*e\n", FLT_DIG, FLT_EPSILON); fprintf(rubyFloat," DBL_EPSILON = %.*e\n", DBL_DIG, DBL_EPSILON); fprintf(rubyFloat,"end\n"); return 0; } which generates an extension to the Float class: class Float FLT_EPSILON = 1.192093e-07 DBL_EPSILON = 2.220446049250313e-16 end Of course it would be nice if these (and many other similar machine- dependent limits available via float.h) were part of Ruby proper (see RCR#37 at http://www.rubygarden.com/index.php?topic=RCR). These constants come in handy for RubyUnit's tolerence argument to assert_float_equal and for a host of other numerical analysis situations. FWIW, -- Bil Kleb NASA Langley Research Center Hampton, Virginia, USA