Pure Haskell implementation of Float type?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Pure Haskell implementation of Float type?

Tim Chevalier
Hello,
Is there a pure Haskell implementation of Floats, i.e., one that
(unlike GHC.Float) doesn't use foreign calls for things like
isFloatNegativeZero? I don't care about performance; I'm just looking
for something that doesn't use foreign calls.

Thanks,
Tim

--
Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
"It is easy to keep secrets by being honest in an ironic tone of
voice." -- Andrew Solomon
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pure Haskell implementation of Float type?

Don Stewart-2
catamorphism:
> Hello,
> Is there a pure Haskell implementation of Floats, i.e., one that
> (unlike GHC.Float) doesn't use foreign calls for things like
> isFloatNegativeZero? I don't care about performance; I'm just looking
> for something that doesn't use foreign calls.
>

Huh, what's the use case?

-- Don
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pure Haskell implementation of Float type?

Tim Chevalier
On 1/20/09, Don Stewart <[hidden email]> wrote:

> catamorphism:
>
> > Hello,
>  > Is there a pure Haskell implementation of Floats, i.e., one that
>  > (unlike GHC.Float) doesn't use foreign calls for things like
>  > isFloatNegativeZero? I don't care about performance; I'm just looking
>  > for something that doesn't use foreign calls.
>  >
>
>
> Huh, what's the use case?
>

I'm implementing a compiler that doesn't support foreign calls (yet).

Cheers,
Tim

--
Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
"I cannot remember a time when I did not take it as understood that
everybody has at least two, if not twenty-two, sides to him." --
Robertson Davies
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pure Haskell implementation of Float type?

Lennart Augustsson
Do you have Integer?

On Wed, Jan 21, 2009 at 12:23 AM, Tim Chevalier <[hidden email]> wrote:

> On 1/20/09, Don Stewart <[hidden email]> wrote:
>> catamorphism:
>>
>> > Hello,
>>  > Is there a pure Haskell implementation of Floats, i.e., one that
>>  > (unlike GHC.Float) doesn't use foreign calls for things like
>>  > isFloatNegativeZero? I don't care about performance; I'm just looking
>>  > for something that doesn't use foreign calls.
>>  >
>>
>>
>> Huh, what's the use case?
>>
>
> I'm implementing a compiler that doesn't support foreign calls (yet).
>
> Cheers,
> Tim
>
> --
> Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
> "I cannot remember a time when I did not take it as understood that
> everybody has at least two, if not twenty-two, sides to him." --
> Robertson Davies
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pure Haskell implementation of Float type?

Tim Chevalier
On 1/20/09, Lennart Augustsson <[hidden email]> wrote:
> Do you have Integer?
>

Yes (with the integer-simple library -- I was hoping there was some
analogue of integer-simple for Float, although Don didn't think there
was one).

-t

--
Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
"Having the gumption to live different *and* the sense to let
everybody else live different. That's the hardest thing, hands down."
-- Alice Venable Middleton
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pure Haskell implementation of Float type?

Lennart Augustsson
There's the numbers package which contains BigFloat.  You can pick
your own precision, but it's not IEEE.
It's actually base 10 floats which makes it more fun (actually, the
iEEE standard will cover base 10 floats in the future).

  -- Lennart

On Wed, Jan 21, 2009 at 12:44 AM, Tim Chevalier <[hidden email]> wrote:

> On 1/20/09, Lennart Augustsson <[hidden email]> wrote:
>> Do you have Integer?
>>
>
> Yes (with the integer-simple library -- I was hoping there was some
> analogue of integer-simple for Float, although Don didn't think there
> was one).
>
> -t
>
> --
> Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt
> "Having the gumption to live different *and* the sense to let
> everybody else live different. That's the hardest thing, hands down."
> -- Alice Venable Middleton
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pure Haskell implementation of Float type?

Ertugrul Söylemez
In reply to this post by Tim Chevalier
"Tim Chevalier" <[hidden email]> wrote:

> Is there a pure Haskell implementation of Floats, i.e., one that
> (unlike GHC.Float) doesn't use foreign calls for things like
> isFloatNegativeZero? I don't care about performance; I'm just looking
> for something that doesn't use foreign calls.

You can easily do it yourself:

  data MyFloat m e
    = MyFloat m e | MyInfinity Bool | MyNaN

A number x is represented in floating point as x = m * b^e, where m is
called the mantissa, e the exponent and b the base.  For performance
reasons, usually b = 2 is chosen and both m and e are integers with
fixed size.  You'll find it useful to have a 'normalize' function, which
'moves the point', such that the mantissa isn't divisible by b, if
possible.


Greets,
Ertugrul.


--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pure Haskell implementation of Float type?

Henning Thielemann-4
In reply to this post by Lennart Augustsson
Lennart Augustsson schrieb:
> There's the numbers package which contains BigFloat.  You can pick
> your own precision, but it's not IEEE.
> It's actually base 10 floats which makes it more fun (actually, the
> iEEE standard will cover base 10 floats in the future).

Actually, all of the arbitrary precision real number implementations may
be of interest for you:

http://haskell.org/haskellwiki/Applications_and_libraries/Mathematics#Number_representations

The NumericPrelude implementation by me, however, sometimes uses the
Double implementation for speedup.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe