Anonymous user
Test integerness: Difference between revisions
Updated to work with Nim 1.4: added parentheses around negative floats. Changed "is_integer" to "isInteger" to follow Nim guidelines. Done miscellaneous minor changes.
m (→{{header|Nim}}) |
(Updated to work with Nim 1.4: added parentheses around negative floats. Changed "is_integer" to "isInteger" to follow Nim guidelines. Done miscellaneous minor changes.) |
||
Line 1,680:
{{out}}<pre>{False,False,True,False}</pre>
=={{header|Nim}}==
::– SomeInteger: integer types, signed or unsigned, 8,16,32,or 64 bits
::– SomeFloat: floating point, 32 or 64 bits
::– SomeNumber: SomeInteger or SomeFloat
::– Rational: rational type; a numerator and denominator, of any (identical) SomeInteger type
::– Complex: complex type; real and imaginary of any (identical) SomeFloat type
<lang nim>import complex, rationals, math, fenv, sugar
func
when T is Complex:
x.im == 0 and x.re.
elif T is Rational:
x.dup(reduce).den == 1
Line 1,703 ⟶ 1,704:
true
# Floats.
assert not
assert not INF.isInteger # Indeed, "ceil(INF) - INF" is NaN.
assert not (-5e-2).
assert (
assert
assert not 24.999999.
assert 24.999999.isInteger(tolerance = 0.00001)
assert not (1.0'f64 + epsilon(float64)).is_integer▼
assert not (
# Rationals.
assert not (5 // 3).is_integer▼
assert not (
assert (
# Unsigned integers.
assert 3u.isInteger
# Complex numbers.
assert not (1.0 + im 1.0).is_integer▼
assert not (
=={{header|ooRexx}}==
|