1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
discard """
output: '''
@[1.0, 2.0, 3.0]
@[1.0, 2.0, 3.0]
'''
"""
# bug #6406
import sequtils
proc remap1(s: seq[int], T: typedesc): seq[T] =
s.map do (x: int) -> T:
x.T
proc remap2[T](s: seq[int], typ: typedesc[T]): seq[T] =
s.map do (x: int) -> T:
x.T
echo remap1(@[1,2,3], float)
echo remap2(@[1,2,3], float)
#--------------------------------------------------------------------
# conversion to bool, issue #13744
proc test_conv_to_bool =
var
i0 = 0
i1 = 1
ih = high(uint)
il = low(int)
f0 = 0.0
f1 = 1.0
fh = Inf
fl = -Inf
f_nan = NaN
doAssert(bool(i0) == false)
doAssert(bool(i1) == true)
doAssert(bool(-i1) == true)
doAssert(bool(il) == true)
doAssert(bool(ih) == true)
doAssert(bool(f0) == false)
doAssert(bool(-f0) == false)
doAssert(bool(f1) == true)
doAssert(bool(-f1) == true)
doAssert(bool(fh) == true)
doAssert(bool(fl) == true)
doAssert(bool(fnan) == true) # NaN to bool gives true according to standard
static:
doAssert(bool(0) == false)
doAssert(bool(-1) == true)
doAssert(bool(2) == true)
doAssert(bool(NaN) == true)
doAssert(bool(0.0) == false)
doAssert(bool(-0.0) == false)
test_conv_to_bool()
test_conv_to_bool()
|