Created
November 22, 2016 20:47
-
-
Save joeykrug/43f2cba0593c2216affc3fa567d97c32 to your computer and use it in GitHub Desktop.
float
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
type float: [a, b, c] | |
macro float($x) + float($y): | |
if(!safeToAdd($x, $y)): | |
throw() | |
float($x + $y) | |
macro float($x) - float($y): | |
if(!safeToSubtract($x, $y)): | |
throw() | |
float($x - $y) | |
macro float($x) * float($y): | |
if(!safeToMultiply($x, $y)): | |
throw() | |
float($x * $y / 10^18) | |
macro float($x) / float($y): | |
if($y == 0): | |
throw() | |
float($x * 10^18 / $y) | |
macro unfloat($x): | |
$x / 10^18 | |
macro floatfy($x): | |
float($x * 10^18) | |
macro float($x) = float($y): | |
$x = $y | |
macro with(float($x), float($y), $z): | |
with($x, $y, $z) | |
macro safeToAdd($a, $b): | |
$c = $a + $b | |
($c >= $a && $c >= $b) | |
macro safeToSubtract($a, $b): | |
($b <= $a) | |
macro safeToMultiply($a, $b): | |
$c = $a * $b | |
($a == 0 || ($c / $a) == $b) | |
def test(): | |
a = floatfy(25) | |
b = a / floatfy(2) | |
c = b * b | |
return(unfloat(c)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment