[Haskell-cafe] Fortran mixed mode arithmetic expressions ->
nowgate at yahoo.com
Mon Oct 26 15:13:14 EDT 2009
Got it. No doubt some of this figures into why I was beaten bloody by ghci last night. Is there a number "tree" somewhere that shows the heirarchy?
--- On Mon, 10/26/09, Daniel Fischer <daniel.is.fischer at web.de> wrote:
From: Daniel Fischer <daniel.is.fischer at web.de>
Subject: Re: [Haskell-cafe] Fortran mixed mode arithmetic expressions -> Haskell
To: "michael rice" <nowgate at yahoo.com>, haskell-cafe at haskell.org
Date: Monday, October 26, 2009, 1:09 PM
Am Monday 26 October 2009 17:24:46 schrieben Sie:
> Being new to Haskell, I take it (^) and (^^) would be the preferred
> exponential "operator." When (how,where,why) would one use (**)?
The beasts have different types and are for different things:
Prelude> :i (^)
(^) :: (Num a, Integral b) => a -> b -> a -- Defined in GHC.Real
infixr 8 ^
This one raises any number to a nonnegative integral power.
A typical implementation would be power by repeated squaring.
Prelude> :i (^^)
(^^) :: (Fractional a, Integral b) => a -> b -> a
-- Defined in GHC.Real
infixr 8 ^^
This one allows also negative powers, so the type of base must allow inversion, hence it
must belong to Fractional. The exponent must still be an integer, you can't use this for
n-th roots or similar.
A typical implementation would be power by repeated squaring, followed by (1/) if the
exponent is negative.
Prelude> :i (**)
class (Fractional a) => Floating a where
(**) :: a -> a -> a
-- Defined in GHC.Float
infixr 8 **
This one raises a floating point number to an arbitrary power, so you can use it for n-th
A typical implementation would be
b ** e = exp (e*log b).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe