-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ base ] Add bindings for ieee
Double
number consts (#3116)
- Loading branch information
1 parent
a945b5d
commit d80bc15
Showing
30 changed files
with
415 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
||| Various IEEE floating-point number constants | ||
module Data.Double | ||
|
||
||| Largest number that can be added to a floating-point number without changing | ||
||| its value, i.e. `1.0 + unitRoundoff == 1.0`. | ||
%foreign "scheme:blodwen-calcFlonumUnitRoundoff" | ||
"node:lambda:()=>Number.EPSILON / 2" | ||
export | ||
unitRoundoff : Double | ||
|
||
||| Machine epsilon is the smallest floating-point number that distinguishes two | ||
||| floating-point numbers; the step size on the floating-point number line. | ||
-- /!\ See `support/racket/support.rkt:42-45` | ||
-- %foreign "scheme,chez:blodwen-calcFlonumEpsilon" | ||
-- "scheme,racket:blodwen-flonumEpsilon" | ||
%foreign "scheme:blodwen-calcFlonumEpsilon" | ||
"node:lambda:()=>Number.EPSILON" | ||
export | ||
epsilon : Double | ||
|
||
|
||
||| Not a number, e.g. `0.0 / 0.0`. Never equal to anything, including itself. | ||
%foreign "scheme:blodwen-flonumNaN" | ||
"node:lambda:()=>Number.NaN" | ||
export | ||
nan : Double | ||
|
||
|
||
||| Positive Infinity. Can be negated to obtain Negative Infinity. | ||
%foreign "scheme:blodwen-flonumInf" | ||
"node:lambda:()=>Infinity" | ||
export | ||
inf : Double | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Data.Double | ||
|
||
-- adding the unit roundoff to a Double should not modify it | ||
|
||
testOnePlusUR : Bool | ||
testOnePlusUR = 1.0 + unitRoundoff == 1.0 | ||
|
||
testURPlusOne : Bool | ||
testURPlusOne = unitRoundoff + 1.0 == 1.0 | ||
|
||
testURComm : Bool | ||
testURComm = testOnePlusUR == testURPlusOne | ||
|
||
|
||
-- the machine epsilon should be double the unit roundoff | ||
|
||
testEps2UR : Bool | ||
testEps2UR = epsilon == unitRoundoff * 2.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
1/1: Building URandEpsilon (URandEpsilon.idr) | ||
Main> Main> True | ||
Main> True | ||
Main> True | ||
Main> True | ||
Main> | ||
Bye for now! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- we need to exec to get the prim__* functions to disappear | ||
:exec printLn testOnePlusUR | ||
:exec printLn testURPlusOne | ||
:exec printLn testURComm | ||
:exec printLn testEps2UR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
idris2 URandEpsilon.idr < input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Data.Double | ||
|
||
-- undefined things are NaN | ||
divZeroZero : Double | ||
divZeroZero = 0.0 / 0.0 | ||
|
||
-- NaN with anything is NaN | ||
|
||
nanPlus : Double | ||
nanPlus = 1.0 + nan | ||
|
||
nanSub : Double | ||
nanSub = 1.0 - nan | ||
|
||
nanMult : Double | ||
nanMult = 2.0 * nan | ||
|
||
nanDiv : Double | ||
nanDiv = nan / 2.0 | ||
|
||
-- neg NaN is still NaN | ||
negNaN : Double | ||
negNaN = negate nan | ||
|
||
-- NaNs are never equal | ||
nansNotEq : Bool | ||
nansNotEq = nan == nan | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
1/1: Building NaN (NaN.idr) | ||
Main> Main> +nan.0 | ||
Main> +nan.0 | ||
Main> +nan.0 | ||
Main> +nan.0 | ||
Main> +nan.0 | ||
Main> +nan.0 | ||
Main> False | ||
Main> | ||
Bye for now! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- we need to exec to get the prim__* functions to disappear | ||
:exec printLn divZeroZero | ||
:exec printLn nanPlus | ||
:exec printLn nanSub | ||
:exec printLn nanMult | ||
:exec printLn nanDiv | ||
:exec printLn negNaN | ||
:exec printLn nansNotEq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
idris2 NaN.idr < input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Data.Double | ||
|
||
-- negating positive inf (should give negative inf) | ||
negInf : Double | ||
negInf = negate inf | ||
|
||
-- dividing non-zero by zero tends to infinity | ||
divNZbyZero : Bool | ||
divNZbyZero = 1.0 / 0.0 == inf | ||
|
||
-- adding pos-inf to pos-inf gives pos-inf | ||
addPosInfs : Bool | ||
addPosInfs = inf + inf == inf | ||
|
||
-- subbing inf from neg-inf gives neg-inf | ||
subNegInfs : Bool | ||
subNegInfs = -inf - inf == -inf | ||
|
||
-- subtracting pos-inf from pos-inf is nan | ||
-- (can't use `==` because no nans are equal) | ||
subPosInf : Double | ||
subPosInf = inf - inf | ||
|
||
-- adding pos-inf to neg-inf is nan | ||
-- (can't use `==` because no nans are equal) | ||
addNegInf : Double | ||
addNegInf = -inf + inf | ||
|
||
-- neg-inf by neg-inf gives pos-inf | ||
squareNegInfIsPosInf : Bool | ||
squareNegInfIsPosInf = pow (-inf) 2 == inf | ||
|
||
-- pos-inf by pos-inf gives pos-inf | ||
squarePosInfIsPosInf : Bool | ||
squarePosInfIsPosInf = pow inf 2 == inf | ||
|
||
-- pos-inf by neg-inf is neg-inf | ||
multInfSignFlip : Bool | ||
multInfSignFlip = inf * (-inf) == -inf | ||
|
||
-- pos-inf is equal to some other pos-inf | ||
posInfIsPosInf : Bool | ||
posInfIsPosInf = inf == pow inf 2 | ||
|
||
-- neg-inf is equal to some other neg-inf | ||
negInfIsNegInf : Bool | ||
negInfIsNegInf = -inf == pow (-inf) 3 | ||
|
||
-- pos-inf is not neg-inf | ||
posInfEqNegInf : Bool | ||
posInfEqNegInf = inf == -inf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
1/1: Building Inf (Inf.idr) | ||
Main> Main> -inf.0 | ||
Main> True | ||
Main> True | ||
Main> True | ||
Main> +nan.0 | ||
Main> +nan.0 | ||
Main> True | ||
Main> True | ||
Main> True | ||
Main> True | ||
Main> True | ||
Main> False | ||
Main> | ||
Bye for now! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- we need to exec to get the prim__* functions to disappear | ||
:exec printLn negInf | ||
:exec printLn divNZbyZero | ||
:exec printLn addPosInfs | ||
:exec printLn subNegInfs | ||
:exec printLn subPosInf | ||
:exec printLn addNegInf | ||
:exec printLn squareNegInfIsPosInf | ||
:exec printLn squarePosInfIsPosInf | ||
:exec printLn multInfSignFlip | ||
:exec printLn posInfIsPosInf | ||
:exec printLn negInfIsNegInf | ||
:exec printLn posInfEqNegInf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
idris2 Inf.idr < input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Data.Double | ||
|
||
-- adding the rounding unit to a Double should not modify it | ||
|
||
testOnePlusUR : Bool | ||
testOnePlusUR = 1.0 + unitRoundoff == 1.0 | ||
|
||
testURPlusOne : Bool | ||
testURPlusOne = unitRoundoff + 1.0 == 1.0 | ||
|
||
testURComm : Bool | ||
testURComm = testOnePlusUR == testURPlusOne | ||
|
||
|
||
-- the machine epsilon should be double the rounding unit | ||
|
||
testEps2UR : Bool | ||
testEps2UR = epsilon == unitRoundoff * 2.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
1/1: Building URandEpsilon (URandEpsilon.idr) | ||
Main> Main> True | ||
Main> True | ||
Main> True | ||
Main> True | ||
Main> | ||
Bye for now! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- we need to exec to get the prim__* functions to disappear | ||
:exec printLn testOnePlusUR | ||
:exec printLn testURPlusOne | ||
:exec printLn testURComm | ||
:exec printLn testEps2UR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
idris2 URandEpsilon.idr < input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Data.Double | ||
|
||
-- undefined things are NaN | ||
divZeroZero : Double | ||
divZeroZero = 0.0 / 0.0 | ||
|
||
-- NaN with anything is NaN | ||
|
||
nanPlus : Double | ||
nanPlus = 1.0 + nan | ||
|
||
nanSub : Double | ||
nanSub = 1.0 - nan | ||
|
||
nanMult : Double | ||
nanMult = 2.0 * nan | ||
|
||
nanDiv : Double | ||
nanDiv = nan / 2.0 | ||
|
||
-- neg NaN is still NaN | ||
negNaN : Double | ||
negNaN = negate nan | ||
|
||
-- NaNs are never equal | ||
nansNotEq : Bool | ||
nansNotEq = nan == nan | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
1/1: Building NaN (NaN.idr) | ||
Main> Main> NaN | ||
Main> NaN | ||
Main> NaN | ||
Main> NaN | ||
Main> NaN | ||
Main> NaN | ||
Main> False | ||
Main> | ||
Bye for now! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- we need to exec to get the prim__* functions to disappear | ||
:exec printLn divZeroZero | ||
:exec printLn nanPlus | ||
:exec printLn nanSub | ||
:exec printLn nanMult | ||
:exec printLn nanDiv | ||
:exec printLn negNaN | ||
:exec printLn nansNotEq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
idris2 NaN.idr < input |
Oops, something went wrong.