# Integers too big for floats

### From HaskellWiki

Although floating point types can represent a large range of magnitudes,

you will sometimes have to cope with integers that are larger than what is representable byDouble

## 1 Dividing large integers to floats

Consider

factorial :: (Enum a, Num a) => a -> a factorial k = product [1..k]

factorial 777

Double

Integer

factorial 777 / factorial 778

Double

Integer

Integer

Double

Is there a variant of division which accepts big integers and emits floating point numbers?

Actually you can represent the fractionfactorial 777 / factorial 778

Rational

and convert that to a floating point number:

fromRational (factorial 777 % factorial 778)

fromRational

But there is an efficiency problem:

BeforefromRational

%

Rational

However that's a hack, since it is not sure that other operations work well on non-cancelled fractions.

You had to importGHC.Real

## 2 See also

- Haskell Cafe on "about integer and float operations"
- Generic number type