diff options
author | Simon Hafner <hafnersimon@gmail.com> | 2015-04-04 16:44:59 -0500 |
---|---|---|
committer | Simon Hafner <hafnersimon@gmail.com> | 2015-04-04 16:44:59 -0500 |
commit | 4ea5f3e6e6fe790663735726923210ba10047edc (patch) | |
tree | d60b773559431cbbcc745c6e2dcb46fa07263f2a /lib/pure | |
parent | a83286192ff286ce01f2223e16b1135a996c9f6c (diff) | |
download | Nim-4ea5f3e6e6fe790663735726923210ba10047edc.tar.gz |
no side effects on math procs, fixes #2458
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/math.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim index c902af381..aa64933fb 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -152,6 +152,7 @@ proc randomize*(seed: int) {.benign.} ## Note: Does nothing for the JavaScript target, ## as JavaScript does not support this. +{.push noSideEffect.} when not defined(JS): proc sqrt*(x: float): float {.importc: "sqrt", header: "<math.h>".} ## computes the square root of `x`. @@ -273,6 +274,8 @@ else: var y = exp(2.0*x) return (y-1.0)/(y+1.0) +{.pop.} + proc `mod`*(x, y: float): float = result = if y == 0.0: x else: x - y * (x/y).floor @@ -370,3 +373,7 @@ when isMainModule and not defined(JS): for i in 0..SIZE-1: assert buf[i] == random(high(int)), "non deterministic random seeding" echo "random values equal after reseeding" + + # Check for no side effect annotation + proc mySqrt(num: float): float {.noSideEffect.} = + return sqrt(num) |