Show
Ignore:
Timestamp:
04/06/06 15:44:58 (3 years ago)
Author:
audreyt
svk:copy_cache_prev:
13015
Message:

* Fractional numbers now work with "%"; arith.t passes again.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim/Numeric.hs

    r9309 r9856  
    8989    = if y' == 0 then err else return . VInt $ x' `mod` y' 
    9090    | VInt x' <- x, VRat y' <- y 
    91     = if y' == 0 then err else return . VInt $ x' `mod` (truncate y') 
     91    = if y' == 0 then err else return . VRat $ (x' % 1) `fmod` y' 
    9292    | VRat x' <- x, VInt y' <- y 
    93     = if y' == 0 then err else return . VInt $ (truncate x') `mod` y' 
     93    = if y' == 0 then err else return . VRat $ x' `fmod` (y' % 1) 
    9494    | VRat x' <- x, VRat y' <- y 
    95     = if y' == 0 then err else return . VInt $ (truncate x') `mod` (truncate y') 
    96     | VRef ref <- x 
    97     = do 
    98         x' <- readRef ref 
    99         op2Modulus x' y 
    100     | VRef ref <- y 
    101     = do 
    102         y' <- readRef ref 
    103         op2Modulus x y' 
     95    = if y' == 0 then err else return . VRat $ x' `fmod` y' 
    10496    | otherwise      -- pray for the best 
    105     = op2Int mod x y -- typeErr 
     97    = op2Num fmod x y 
    10698    where 
    10799    err = fail "Illegal modulus zero" 
     100    fmod :: RealFrac a => a -> a -> a 
     101    fmod x y = let mod = x - (fromIntegral (truncate (x/y)) * y) in 
     102        if signum y * signum mod < 0 then mod + y else mod