Dividing Floats

Daniel Russell djrussell@kingston.ac.uk
Thu, 31 May 2001 17:25:46 +0100 (BST)


> Can anyone please help me.
 
> How can you divide two floats? (and return a float, even if they divide
> equally)
 
> Ie (something like...)     div 2.4 1.2 ---> 2.0
 
The above doesn't work since div can only be applied to integral numbers:

        div :: Integral a => a -> a -> a


What you need is the operator (/) which can only be applied to fractional 
numbers:

        (/) :: Fractional a => a -> a -> a 

For example:
                        2.4 / 1.2  ---> 2.0
                or    (/) 2.4 1.2  ---> 2.0


Dan Russell
Kingston University