libm icon indicating copy to clipboard operation
libm copied to clipboard

Possible errors in some constants?

Open DeliciousHair opened this issue 1 year ago • 2 comments

Sorry, keyboard flaked out there, hence the open-and-close...

Anyhow, was looking at some math functions like sqrtf() and noticed some oddness / inconsistencies that I thought was worth asking about at the very least. In particular, in sqrtf for example, there is:

const TINY: f32 = 1.0e-30;

while in pow there is:

const TWO53: f64 = 9007199254740992.0; /* 0x43400000_00000000 */
const HUGE: f64 = 1.0e300;
const TINY: f64 = 1.0e-300;

None of these are consistent with the FORTRAN values I assume the concepts are based on. For example:

      PROGRAM SOME_F64_CONSTANTS

      DOUBLE PRECISION   ONE, ZERO
      PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
      DOUBLE PRECISION   EPS, SFMIN, SMALL, BIG

      INTRINSIC          EPSILON, HUGE, TINY

      EPS = EPSILON(ZERO)
      SFMIN = TINY(ZERO)
      SMALL = ONE / HUGE(ZERO)
      BIG = HUGE(ONE)

      PRINT *, "  EPS =", EPS
      PRINT *, "SFMIN =", SFMIN
      PRINT *, "SMALL =", SMALL
      PRINT *, "  BIG =", BIG

      END PROGRAM SOME_f64_CONSTANTS

spits out:

   EPS =   2.2204460492503131E-016
 SFMIN =   2.2250738585072014E-308
 SMALL =   5.5626846462680035E-309
   BIG =   1.7976931348623157E+308

Not sure how big the impact of this is, but I suspect it's not zero?

DeliciousHair avatar Mar 15 '23 02:03 DeliciousHair

I don't think these are errors. These constants come directly from the C code which was ported to Rust.

Amanieu avatar Mar 21 '23 14:03 Amanieu

Fair point, but all that means is that the C-code has not used the IEEE-754 standard either :-)

DeliciousHair avatar Mar 21 '23 23:03 DeliciousHair