Changeset 15201 for src/Pugs/Prim.hs

Show
Ignore:
Timestamp:
02/06/07 21:28:57 (22 months ago)
Author:
audreyt
Message:

* Numeric primitives for complex numbers.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim.hs

    r15165 r15201  
    153153op1 "sqrt" = op1Floating sqrt 
    154154op1 "atan" = op1Floating atan 
     155op1 "post:i" = \x -> do 
     156    n <- fromVal x 
     157    return $ VComplex (0 :+ n) 
    155158op1 "post:++" = \x -> atomicEval $ do 
    156159    ref <- fromVal x 
     
    590593op1 "hex"   = fail "hex() is not part of Perl 6 - use :16() instead." 
    591594op1 "oct"   = fail "oct() is not part of Perl 6 - use :8() instead." 
    592 op1 "log"   = op1Cast (VNum . log) 
    593 op1 "log10" = op1Cast (VNum . logBase 10) 
     595op1 "log"   = op1Floating log 
     596op1 "log10" = op1Floating (logBase 10) 
    594597op1 "from"  = op1Cast (castV . matchFrom) 
    595598op1 "to"    = op1Cast (castV . matchTo) 
     
    940943op2 "cmp"= op2OrdNumStr 
    941944op2 "leg"= op2Ord vCastStr 
    942 op2 "<=>"= op2Ord vCastRat 
     945op2 "<=>"= op2OrdNumeric compare 
    943946op2 ".." = op2Range 
    944947op2 "..^" = op2RangeExclRight 
    945948op2 "^.." = op2RangeExclLeft 
    946949op2 "^..^" = op2RangeExclBoth 
    947 op2 "!=" = op2Cmp vCastRat (/=) 
    948 op2 "==" = op2Cmp vCastRat (==) 
    949 op2 "<"  = op2Cmp vCastRat (<) 
    950 op2 "<=" = op2Cmp vCastRat (<=) 
    951 op2 ">"  = op2Cmp vCastRat (>) 
    952 op2 ">=" = op2Cmp vCastRat (>=) 
     950op2 "!=" = op2OrdNumeric (/=) 
     951op2 "==" = op2OrdNumeric (==) 
     952op2 "<"  = op2OrdNumeric (<) 
     953op2 "<=" = op2OrdNumeric (<=) 
     954op2 ">"  = op2OrdNumeric (>) 
     955op2 ">=" = op2OrdNumeric (>=) 
    953956op2 "ne" = op2Cmp vCastStr (/=) 
    954957op2 "eq" = op2Cmp vCastStr (==) 
     
    10581061op2 "exp" = \x y -> if defined y 
    10591062    then op2Num (**) x y 
    1060     else op1Cast (VNum . exp) x 
     1063    else op1Floating exp x 
    10611064op2 "Pugs::Internals::sprintf" = \x y -> do 
    10621065    -- a single argument is all Haskell can really handle. 
     
    15121515op2OrdNumStr x y 
    15131516    | isNumeric x && isNumeric y = op2Ord vCastRat x y 
    1514     | otherwise                  = op2Ord vCastStr x y 
     1517    | otherwise                  = op2OrdNumeric compare x y 
    15151518 
    15161519op3Caller :: Type -> Int -> Val -> Eval Val 
     
    18611864\\n   Num       post    ++      safe   (rw!Num)\ 
    18621865\\n   Num       post    --      safe   (rw!Num)\ 
     1866\\n   Complex   post    i       safe   (Num)\ 
    18631867\\n   Str       spre    ++      safe   (rw!Str)\ 
    18641868\\n   Str       spre    --      safe   (rw!Str)\