Ticket #3134 (new bug)

Opened 4 years ago

Last modified 3 years ago

encodeFloat . decodeFloat

Reported by: roland Owned by:
Priority: normal Milestone: _|_
Component: Prelude Version: 6.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

(0.0/0.0)

NaN

(uncurry encodeFloat . decodeFloat) (0.0/0.0)

-Infinity

It seems reasonable to expect NaN here.

Change History

Changed 4 years ago by simonmar

  • difficulty set to Unknown
  • milestone set to _|_

Interesting, I thought we had a very old ticket about this, but I can't seem to find it.

Anyway, I suppose the issue is what the representation of NaN and Infinity should be in the output of decodeFloat. There is no provision for NaN and Infinity in the Haskell definition of encodeFloat and decodeFloat:

The function decodeFloat applied to a real floating-point number returns the significand expressed as an Integer and an appropriately scaled exponent (an Int). If decodeFloat x yields (m,n), then x is equal in value to mbn, where b is the floating-point radix, and furthermore, either m and n are both zero or else bd-1<=m<bd, where d is the value of floatDigits x. encodeFloat performs the inverse of this transformation.

from Section 6.4.6,  http://haskell.org/onlinereport/basic.html

Changed 3 years ago by simonmar

  • failure set to None/Unknown

See also #3174

Maybe the right thing is for decodeFloat applied to NaN or Infinity to be an error, rather than silently succeeding with a bogus value.

Changed 3 years ago by daniel.is.fischer

For the particular values which decodeFloat returns for NaNs (Float and Double), it would be easy to add a test to integer_cbits_encodeType, that would probably even be not too expensive.

However, those functions look a little dubious. Remind me to look at them again some time, maybe there's speed and correctness to be gained.

Note: See TracTickets for help on using tickets.