adopt backend implementations of pow (#2334)

This commit is contained in:
Joel Berkeley 2022-03-03 23:39:25 +00:00 committed by GitHub
parent f317555967
commit f436388a6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 171 additions and 2 deletions

View File

@ -794,7 +794,7 @@ log x = prim__doubleLog x
public export
pow : Double -> Double -> Double
pow x y = exp (y * log x) -- prim__doublePow x y
pow x y = prim__doublePow x y
public export
sin : Double -> Double

View File

@ -170,7 +170,7 @@ schOp StrSubstr [x, y, z] = pure $ op "string-substr" [x, y, z]
-- `e` is Euler's number, which approximates to: 2.718281828459045
schOp DoubleExp [x] = pure $ op "flexp" [x] -- Base is `e`. Same as: `pow(e, x)`
schOp DoubleLog [x] = pure $ op "fllog" [x] -- Base is `e`.
schOp DoublePow [x, y] = pure $ op "expt" [x, y]
schOp DoublePow [x, y] = pure $ op "flexpt" [x, y]
schOp DoubleSin [x] = pure $ op "flsin" [x]
schOp DoubleCos [x] = pure $ op "flcos" [x]
schOp DoubleTan [x] = pure $ op "fltan" [x]

View File

@ -0,0 +1,90 @@
nan, inf : Double
nan = 0.0 / 0.0
inf = 1.0 / 0.0
powDoubleCases : List Double
powDoubleCases = [
pow (-inf) (-inf),
pow (-inf) (-2),
pow (-inf) (-0.5),
pow (-inf) 0,
pow (-inf) 0.5,
pow (-inf) 2,
pow (-inf) inf,
pow (-inf) nan,
pow (-2) (-inf),
pow (-2) (-2),
pow (-2) (-0.5),
pow (-2) 0,
pow (-2) 0.5,
pow (-2) 2,
pow (-2) inf,
pow (-2) nan,
pow (-0.5) (-inf),
pow (-0.5) (-2),
pow (-0.5) (-0.5),
pow (-0.5) 0,
pow (-0.5) 0.5,
pow (-0.5) 2,
pow (-0.5) inf,
pow (-0.5) nan,
pow 0 (-inf),
pow 0 (-2),
pow 0 (-0.5),
pow 0 0,
pow 0 0.5,
pow 0 2,
pow 0 inf,
pow 0 nan,
pow 0.5 (-inf),
pow 0.5 (-2),
pow 0.5 (-0.5),
pow 0.5 0,
pow 0.5 0.5,
pow 0.5 2,
pow 0.5 inf,
pow 0.5 nan,
pow 1 (-inf),
pow 1 (-2),
pow 1 (-0.5),
pow 1 0,
pow 1 0.5,
pow 1 2,
pow 1 inf,
pow 1 nan,
pow 2 (-inf),
pow 2 (-2),
pow 2 (-0.5),
pow 2 0,
pow 2 0.5,
pow 2 2,
pow 2 inf,
pow 2 nan,
pow inf (-inf),
pow inf (-2),
pow inf (-0.5),
pow inf 0,
pow inf 0.5,
pow inf 2,
pow inf inf,
pow inf nan,
pow nan (-inf),
pow nan (-2),
pow nan (-0.5),
pow nan 0,
pow nan 0.5,
pow nan 2,
pow nan inf,
pow nan nan
]
main : IO ()
main = traverse_ printLn powDoubleCases

View File

@ -0,0 +1,74 @@
1/1: Building Types (Types.idr)
Main> 0.0
0.0
0.0
1.0
+inf.0
+inf.0
+inf.0
+nan.0
0.0
0.25
+nan.0
1.0
+nan.0
4.0
+inf.0
+nan.0
+inf.0
4.0
+nan.0
1.0
+nan.0
0.25
0.0
+nan.0
+inf.0
+inf.0
+inf.0
1.0
0.0
0.0
0.0
+nan.0
+inf.0
4.0
1.4142135623730951
1.0
0.7071067811865476
0.25
0.0
+nan.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0.0
0.25
0.7071067811865476
1.0
1.4142135623730951
4.0
+inf.0
+nan.0
0.0
0.0
0.0
1.0
+inf.0
+inf.0
+inf.0
+nan.0
+nan.0
+nan.0
+nan.0
1.0
+nan.0
+nan.0
+nan.0
+nan.0
Main> Bye for now!

View File

@ -0,0 +1,2 @@
:exec main
:q

3
tests/prelude/double001/run Executable file
View File

@ -0,0 +1,3 @@
rm -rf build
$1 --no-banner --no-color --console-width 0 Types.idr < input