diff options
Diffstat (limited to 'lib/pure/math.nim')
-rw-r--r-- | lib/pure/math.nim | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim index 2f7a696b9..97c7b0e05 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -40,17 +40,6 @@ const ## after the decimal point ## for Nimrod's ``float`` type. -type - TFloatClass* = enum ## describes the class a floating point value belongs to. - ## This is the type that is returned by `classify`. - fcNormal, ## value is an ordinary nonzero floating point value - fcSubnormal, ## value is a subnormal (a very small) floating point value - fcZero, ## value is zero - fcNegZero, ## value is the negative zero - fcNan, ## value is Not-A-Number (NAN) - fcInf, ## value is positive infinity - fcNegInf ## value is negative infinity - proc classify*(x: float): TFloatClass = ## classifies a floating point value. Returns `x`'s class as specified by ## `TFloatClass`. @@ -219,7 +208,7 @@ when not defined(JS): proc randomize(seed: int) = srand(cint(seed)) - when defined(srand48): srand48(seed) + when declared(srand48): srand48(seed) proc random(max: int): int = result = int(rand()) mod max @@ -279,8 +268,13 @@ proc `mod`*(x, y: float): float = result = if y == 0.0: x else: x - y * (x/y).floor proc random*[T](x: TSlice[T]): T = + ## For a slice `a .. b` returns a value in the range `a .. b-1`. result = random(x.b - x.a) + x.a - + +proc random[T](a: openarray[T]): T = + ## returns a random element from the openarray `a`. + result = a[random(a.low..a.len)] + type TRunningStat* {.pure,final.} = object ## an accumulator for statistical data n*: int ## number of pushed data |