# Stricness of floor etc

Ian Lynagh igloo@earth.li
Tue, 18 Mar 2003 14:00:41 +0000

```On Tue, Mar 18, 2003 at 10:22:52AM -0000, Simon Marlow wrote:
>
> > floor1 :: forall b. (GHC.Real.Integral b) =>
> >           Double -> b
> >             __S L
>
> This floor is the dictionary selector, and for various (complicated
> looking) reasons it is lazy in its dictionary argument.

Aha! Thanks.

> > Of course a strict floor (Double to Int and Integer) is what
> > I'm really
> > hoping for (without having to specify it explicitly with \$!
> > in my code).
>
> There are specialised versions of floor for Double -> Int and Double ->
> Integer.  You *ought* to get good code out if you call floor at one of
> these types.  If not, please send us the example.

Well, with the following module, with the strictnesses in comments, it
seems to me that floor is lazy even when explicitly given the type
Double -> Int - am I confused again? It also looks to me like addition
of unboxed Ints is also treated as being lazy.

import GHC.Base

foo :: Int# -> Int# -> Int#
foo = (+#)                              -- __S LL

bar :: Int -> Int -> Int
bar = (+)                               -- __S U(L)U(L)m

baz :: Integer -> Integer -> Integer
baz = (+)                               -- __S SS

quux :: Double -> Int
quux x = floor x                        -- __S L

-ddump-simpl gives the following for quux:

Str.quux = \ x :: GHC.Float.Double ->
case GHC.Float.properFraction2
@ GHC.Base.Int GHC.Real.\$fIntegralInt x
of wild { (n, r) ->
case r of wild1 { GHC.Float.D# x1 ->
case GHC.Prim.<## x1 0.0 of wild2 {
GHC.Base.True ->
case n of wild11 { GHC.Base.I# x11 ->
GHC.Base.I# (GHC.Prim.-# x11 1)
};
GHC.Base.False -> n
}
}
}

Thanks
Ian

```