no side effects on math procs, fixes #2458
This commit is contained in:
parent
a83286192f
commit
4ea5f3e6e6
1 changed files with 7 additions and 0 deletions
|
|
@ -152,6 +152,7 @@ proc randomize*(seed: int) {.benign.}
|
||||||
## Note: Does nothing for the JavaScript target,
|
## Note: Does nothing for the JavaScript target,
|
||||||
## as JavaScript does not support this.
|
## as JavaScript does not support this.
|
||||||
|
|
||||||
|
{.push noSideEffect.}
|
||||||
when not defined(JS):
|
when not defined(JS):
|
||||||
proc sqrt*(x: float): float {.importc: "sqrt", header: "<math.h>".}
|
proc sqrt*(x: float): float {.importc: "sqrt", header: "<math.h>".}
|
||||||
## computes the square root of `x`.
|
## computes the square root of `x`.
|
||||||
|
|
@ -273,6 +274,8 @@ else:
|
||||||
var y = exp(2.0*x)
|
var y = exp(2.0*x)
|
||||||
return (y-1.0)/(y+1.0)
|
return (y-1.0)/(y+1.0)
|
||||||
|
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
proc `mod`*(x, y: float): float =
|
proc `mod`*(x, y: float): float =
|
||||||
result = if y == 0.0: x else: x - y * (x/y).floor
|
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:
|
for i in 0..SIZE-1:
|
||||||
assert buf[i] == random(high(int)), "non deterministic random seeding"
|
assert buf[i] == random(high(int)), "non deterministic random seeding"
|
||||||
echo "random values equal after reseeding"
|
echo "random values equal after reseeding"
|
||||||
|
|
||||||
|
# Check for no side effect annotation
|
||||||
|
proc mySqrt(num: float): float {.noSideEffect.} =
|
||||||
|
return sqrt(num)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue