Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/Prelude/CRealFrac.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module Prelude where

import Ratio(Ratio,(%))

class  (Real a, Fractional a) => RealFrac a  where
    properFraction	:: (Integral b) => a -> (b,a)
    truncate, round	:: (Integral b) => a -> b
    ceiling, floor	:: (Integral b) => a -> b
  
    truncate x	=  case properFraction x of (m,_) -> m
    round x	=  case properFraction x of
		    (n,r) ->
    		      case compare (abs r - fromRational (1%2)) 0 of
    			LT -> n
    		 	EQ -> if even n then n else if r<0 then n-1 else n+1
    			GT ->                       if r<0 then n-1 else n+1
    ceiling x	=  case properFraction x of (n,r) -> if r>0 then n+1 else n
    floor x	=  case properFraction x of (n,r) -> if r<0 then n-1 else n


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.