diff options
| author | Raymond Hogenson <rhogenson@posteo.net> | 2018-05-18 12:01:22 -0800 |
|---|---|---|
| committer | Raymond Hogenson <rhogenson@posteo.net> | 2018-05-18 12:01:22 -0800 |
| commit | fb1f8d3a02908e2fe8c08924c2eacef6b84a7204 (patch) | |
| tree | b128b705019448c44b84c0cc3e0cb65010cb5c71 /RealCalc.hs | |
| parent | Add license information to the top of the files (diff) | |
| download | hsc-fb1f8d3a02908e2fe8c08924c2eacef6b84a7204.tar.zst | |
Support exponentiation
Haskell might make this overcomplicated, but it's a complicated problem
to solve, I suppose. Whatever. It works well.
Diffstat (limited to 'RealCalc.hs')
| -rw-r--r-- | RealCalc.hs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/RealCalc.hs b/RealCalc.hs index 11eebe4..df2e06d 100644 --- a/RealCalc.hs +++ b/RealCalc.hs @@ -54,6 +54,12 @@ simplify (Expr.Times e1 e2) = genericCombine (*) (simplify e1) (simplify e2) simplify (Expr.Div e1 e2) = RFloat (rToDouble (simplify e1) / rToDouble (simplify e2)) +simplify (Expr.Pow e1 e2) = + case (simplify e1, simplify e2) of + (RInt a, RInt b) + | b >= 0 -> RInt (a ^ b) + (a, RInt b) -> RFloat (rToDouble a ^^ b) + (a, RFloat b) -> RFloat (rToDouble a ** b) simplify (Expr.EInt i) = RInt i simplify (Expr.EFloat d) = RFloat d simplify Expr.E = RFloat (exp 1) |
