[Haskell-cafe] Set of reals...?
Keean Schupke
k.schupke at imperial.ac.uk
Sat Oct 30 05:38:40 EDT 2004
I would have thought it would have been sensible to base floating
point maths on the IEEE spec, as thats what most hardware implements,
and there are libraries to emulate it for everything else. Does haskell use
IEEE primitives for things like sin/cos and sqrt? I am really surprised this
area seems so neglected.
I for one would like to see floats and doubles following the IEEE spec,
complete with constructors for +/- Infinity, NaN, and primitives.
Keean
Glynn Clements wrote:
>MR K P SCHUPKE wrote:
>
>
>
>>>Double already has +Inf and -Inf; it's just that Haskell doesn't have
>>>(AFAIK) syntax to write them as constants.
>>>
>>>
>> In the source for the GHC libraries it uses 1/0 for +Infinity
>>and -1/0 for -Infinity, so I assume these are the "official" way to do it.
>>
>>Personally I would define nicer names:
>>
>> positiveInfinity :: Double
>> positiveInfinity = 1/0
>>
>> negativeInfinity :: Double
>> negativeInfinity = -1/0
>>
>>
>
>Or just:
>
> infinity = 1/0
>
>and use -infinity for the negative.
>
>One other nit: isn't the read/show syntax for Haskell98 types supposed
>to valid Haskell syntax?
>
>>From http://www.haskell.org/onlinereport/derived.html#derived-text
>
> The result of show is a syntactically correct Haskell
> expression containing only constants, given the fixity
> declarations in force at the point where the type is declared.
>
>[Note: the above sentecne refers specifically to derived instances,
>but induction would require that it also holds for base types.]
>
>However:
>
> Prelude> let infinity = 1/0 :: Double
> Prelude> show infinity
> "Infinity"
> Prelude> read (show infinity) :: Double
> Infinity
> Prelude> Infinity
>
> <interactive>:1: Data constructor not in scope: `Infinity'
>
>
>
More information about the Haskell-Cafe
mailing list