tmath.nim 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. discard """
  2. targets: "c cpp js"
  3. matrix:"; -d:danger; --mm:refc"
  4. """
  5. # xxx: there should be a test with `-d:nimTmathCase2 -d:danger --passc:-ffast-math`,
  6. # but it requires disabling certain lines with `when not defined(nimTmathCase2)`
  7. import std/math
  8. import std/assertions
  9. # Function for approximate comparison of floats
  10. proc `==~`(x, y: float): bool = abs(x - y) < 1e-9
  11. template main() =
  12. block:
  13. when not defined(js):
  14. # check for no side effect annotation
  15. proc mySqrt(num: float): float {.noSideEffect.} =
  16. # xxx unused
  17. sqrt(num)
  18. # check gamma function
  19. doAssert gamma(5.0) == 24.0 # 4!
  20. doAssert almostEqual(gamma(0.5), sqrt(PI))
  21. doAssert almostEqual(gamma(-0.5), -2 * sqrt(PI))
  22. doAssert lgamma(1.0) == 0.0 # ln(1.0) == 0.0
  23. doAssert almostEqual(lgamma(0.5), 0.5 * ln(PI))
  24. doAssert erf(6.0) > erf(5.0)
  25. doAssert erfc(6.0) < erfc(5.0)
  26. block: # sgn() tests
  27. doAssert sgn(1'i8) == 1
  28. doAssert sgn(1'i16) == 1
  29. doAssert sgn(1'i32) == 1
  30. doAssert sgn(1'i64) == 1
  31. doAssert sgn(1'u8) == 1
  32. doAssert sgn(1'u16) == 1
  33. doAssert sgn(1'u32) == 1
  34. doAssert sgn(1'u64) == 1
  35. doAssert sgn(-12342.8844'f32) == -1
  36. doAssert sgn(123.9834'f64) == 1
  37. doAssert sgn(0'i32) == 0
  38. doAssert sgn(0'f32) == 0
  39. doAssert sgn(-0.0'f64) == 0
  40. doAssert sgn(NegInf) == -1
  41. doAssert sgn(Inf) == 1
  42. doAssert sgn(NaN) == 0
  43. block: # fac() tests
  44. when nimvm: discard
  45. else:
  46. try:
  47. discard fac(-1)
  48. except AssertionDefect:
  49. discard
  50. doAssert fac(0) == 1
  51. doAssert fac(1) == 1
  52. doAssert fac(2) == 2
  53. doAssert fac(3) == 6
  54. doAssert fac(4) == 24
  55. doAssert fac(5) == 120
  56. block: # floorMod/floorDiv
  57. doAssert floorDiv(8, 3) == 2
  58. doAssert floorMod(8, 3) == 2
  59. doAssert floorDiv(8, -3) == -3
  60. doAssert floorMod(8, -3) == -1
  61. doAssert floorDiv(-8, 3) == -3
  62. doAssert floorMod(-8, 3) == 1
  63. doAssert floorDiv(-8, -3) == 2
  64. doAssert floorMod(-8, -3) == -2
  65. doAssert floorMod(8.0, -3.0) == -1.0
  66. doAssert floorMod(-8.5, 3.0) == 0.5
  67. block: # euclDiv/euclMod
  68. doAssert euclDiv(8, 3) == 2
  69. doAssert euclMod(8, 3) == 2
  70. doAssert euclDiv(8, -3) == -2
  71. doAssert euclMod(8, -3) == 2
  72. doAssert euclDiv(-8, 3) == -3
  73. doAssert euclMod(-8, 3) == 1
  74. doAssert euclDiv(-8, -3) == 3
  75. doAssert euclMod(-8, -3) == 1
  76. doAssert euclMod(8.0, -3.0) == 2.0
  77. doAssert euclMod(-8.5, 3.0) == 0.5
  78. doAssert euclDiv(9, 3) == 3
  79. doAssert euclMod(9, 3) == 0
  80. doAssert euclDiv(9, -3) == -3
  81. doAssert euclMod(9, -3) == 0
  82. doAssert euclDiv(-9, 3) == -3
  83. doAssert euclMod(-9, 3) == 0
  84. doAssert euclDiv(-9, -3) == 3
  85. doAssert euclMod(-9, -3) == 0
  86. block: # ceilDiv
  87. doAssert ceilDiv(8, 3) == 3
  88. doAssert ceilDiv(8, 4) == 2
  89. doAssert ceilDiv(8, 5) == 2
  90. doAssert ceilDiv(11, 3) == 4
  91. doAssert ceilDiv(12, 3) == 4
  92. doAssert ceilDiv(13, 3) == 5
  93. doAssert ceilDiv(41, 7) == 6
  94. doAssert ceilDiv(0, 1) == 0
  95. doAssert ceilDiv(1, 1) == 1
  96. doAssert ceilDiv(1, 2) == 1
  97. doAssert ceilDiv(2, 1) == 2
  98. doAssert ceilDiv(2, 2) == 1
  99. doAssert ceilDiv(0, high(int)) == 0
  100. doAssert ceilDiv(1, high(int)) == 1
  101. doAssert ceilDiv(0, high(int) - 1) == 0
  102. doAssert ceilDiv(1, high(int) - 1) == 1
  103. doAssert ceilDiv(high(int) div 2, high(int) div 2 + 1) == 1
  104. doAssert ceilDiv(high(int) div 2, high(int) div 2 + 2) == 1
  105. doAssert ceilDiv(high(int) div 2 + 1, high(int) div 2) == 2
  106. doAssert ceilDiv(high(int) div 2 + 2, high(int) div 2) == 2
  107. doAssert ceilDiv(high(int) div 2 + 1, high(int) div 2 + 1) == 1
  108. doAssert ceilDiv(high(int), 1) == high(int)
  109. doAssert ceilDiv(high(int) - 1, 1) == high(int) - 1
  110. doAssert ceilDiv(high(int) - 1, 2) == high(int) div 2
  111. doAssert ceilDiv(high(int) - 1, high(int)) == 1
  112. doAssert ceilDiv(high(int) - 1, high(int) - 1) == 1
  113. doAssert ceilDiv(high(int) - 1, high(int) - 2) == 2
  114. doAssert ceilDiv(high(int), high(int)) == 1
  115. doAssert ceilDiv(high(int), high(int) - 1) == 2
  116. doAssert ceilDiv(255'u8, 1'u8) == 255'u8
  117. doAssert ceilDiv(254'u8, 2'u8) == 127'u8
  118. when not defined(danger):
  119. doAssertRaises(AssertionDefect): discard ceilDiv(41, 0)
  120. doAssertRaises(AssertionDefect): discard ceilDiv(41, -1)
  121. doAssertRaises(AssertionDefect): discard ceilDiv(-1, 1)
  122. doAssertRaises(AssertionDefect): discard ceilDiv(-1, -1)
  123. doAssertRaises(AssertionDefect): discard ceilDiv(254'u8, 3'u8)
  124. doAssertRaises(AssertionDefect): discard ceilDiv(255'u8, 2'u8)
  125. block: # splitDecimal() tests
  126. doAssert splitDecimal(54.674).intpart == 54.0
  127. doAssert splitDecimal(54.674).floatpart ==~ 0.674
  128. doAssert splitDecimal(-693.4356).intpart == -693.0
  129. doAssert splitDecimal(-693.4356).floatpart ==~ -0.4356
  130. doAssert splitDecimal(0.0).intpart == 0.0
  131. doAssert splitDecimal(0.0).floatpart == 0.0
  132. block: # trunc tests for vcc
  133. doAssert trunc(-1.1) == -1
  134. doAssert trunc(1.1) == 1
  135. doAssert trunc(-0.1) == -0
  136. doAssert trunc(0.1) == 0
  137. # special case
  138. doAssert classify(trunc(1e1000000)) == fcInf
  139. doAssert classify(trunc(-1e1000000)) == fcNegInf
  140. when not defined(nimTmathCase2):
  141. doAssert classify(trunc(0.0/0.0)) == fcNan
  142. doAssert classify(trunc(0.0)) == fcZero
  143. # trick the compiler to produce signed zero
  144. let
  145. f_neg_one = -1.0
  146. f_zero = 0.0
  147. f_nan = f_zero / f_zero
  148. doAssert classify(trunc(f_neg_one*f_zero)) == fcNegZero
  149. doAssert trunc(-1.1'f32) == -1
  150. doAssert trunc(1.1'f32) == 1
  151. doAssert trunc(-0.1'f32) == -0
  152. doAssert trunc(0.1'f32) == 0
  153. doAssert classify(trunc(1e1000000'f32)) == fcInf
  154. doAssert classify(trunc(-1e1000000'f32)) == fcNegInf
  155. when not defined(nimTmathCase2):
  156. doAssert classify(trunc(f_nan.float32)) == fcNan
  157. doAssert classify(trunc(0.0'f32)) == fcZero
  158. block: # divmod
  159. doAssert divmod(int.high, 1) == (int.high, 0)
  160. doAssert divmod(-1073741823, 17) == (-63161283, -12)
  161. doAssert divmod(int32.high, 1.int32) == (int32.high, 0.int32)
  162. doAssert divmod(1073741823.int32, 5.int32) == (214748364.int32, 3.int32)
  163. doAssert divmod(4611686018427387903.int64, 5.int64) == (922337203685477580.int64, 3.int64)
  164. when not defined(js) and (not compileOption("panics")) and compileOption("overflowChecks"):
  165. when nimvm:
  166. discard # cannot catch OverflowDefect here
  167. else:
  168. doAssertRaises(OverflowDefect, (discard divmod(cint.low, -1.cint)))
  169. doAssertRaises(OverflowDefect, (discard divmod(clong.low, -1.clong)))
  170. doAssertRaises(OverflowDefect, (discard divmod(clonglong.low, -1.clonglong)))
  171. doAssertRaises(DivByZeroDefect, (discard divmod(1, 0)))
  172. block: # log
  173. doAssert log(4.0, 3.0) ==~ ln(4.0) / ln(3.0)
  174. doAssert log2(8.0'f64) == 3.0'f64
  175. doAssert log2(4.0'f64) == 2.0'f64
  176. doAssert log2(2.0'f64) == 1.0'f64
  177. doAssert log2(1.0'f64) == 0.0'f64
  178. doAssert classify(log2(0.0'f64)) == fcNegInf
  179. doAssert log2(8.0'f32) == 3.0'f32
  180. doAssert log2(4.0'f32) == 2.0'f32
  181. doAssert log2(2.0'f32) == 1.0'f32
  182. doAssert log2(1.0'f32) == 0.0'f32
  183. doAssert classify(log2(0.0'f32)) == fcNegInf
  184. block: # cumsum
  185. block: # cumsum int seq return
  186. let counts = [1, 2, 3, 4]
  187. doAssert counts.cumsummed == @[1, 3, 6, 10]
  188. let empty: seq[int] = @[]
  189. doAssert empty.cumsummed == @[]
  190. block: # cumsum float seq return
  191. let counts = [1.0, 2.0, 3.0, 4.0]
  192. doAssert counts.cumsummed == @[1.0, 3.0, 6.0, 10.0]
  193. let empty: seq[float] = @[]
  194. doAssert empty.cumsummed == @[]
  195. block: # cumsum int in-place
  196. var counts = [1, 2, 3, 4]
  197. counts.cumsum
  198. doAssert counts == [1, 3, 6, 10]
  199. var empty: seq[int] = @[]
  200. empty.cumsum
  201. doAssert empty == @[]
  202. block: # cumsum float in-place
  203. var counts = [1.0, 2.0, 3.0, 4.0]
  204. counts.cumsum
  205. doAssert counts == [1.0, 3.0, 6.0, 10.0]
  206. var empty: seq[float] = @[]
  207. empty.cumsum
  208. doAssert empty == @[]
  209. block: # ^ compiles for valid types
  210. doAssert: compiles(5 ^ 2)
  211. doAssert: compiles(5.5 ^ 2)
  212. doAssert: compiles(5.5 ^ 2.int8)
  213. doAssert: compiles(5.5 ^ 2.uint)
  214. doAssert: compiles(5.5 ^ 2.uint8)
  215. block:
  216. doAssert: compiles(5.5 ^ 2.2)
  217. when not defined(danger):
  218. doAssertRaises(AssertionDefect): discard (0.0 ^ -5.0)
  219. doAssertRaises(AssertionDefect): discard (-0.0 ^ -5.0)
  220. doAssertRaises(AssertionDefect): discard (-0.0 ^ -5.3)
  221. doAssertRaises(AssertionDefect): discard (-0.0 ^ -4.0)
  222. doAssertRaises(AssertionDefect): discard (-0.0 ^ -5.3)
  223. doAssertRaises(AssertionDefect): discard (-0.0 ^ -4.0)
  224. doAssertRaises(AssertionDefect): discard (-0.0 ^ -4.0)
  225. # Base finite, negative and exponent finite, non-integer returns NaN and raises Error
  226. doAssertRaises(AssertionDefect): discard (-5.5 ^ 2.2)
  227. doAssert: -1.0 ^ Inf == 1.0
  228. doAssert: -1.0 ^ -Inf == 1.0
  229. doAssert: 1.0 ^ Inf == 1.0
  230. doAssert: 1.0 ^ -Inf == 1.0
  231. doAssert: 1.0 ^ -5.4 == 1.0
  232. doAssert: 1.0 ^ 1.0 == 1.0
  233. # ^-Inf or ^Inf returns 0 or Inf depending on base absolute value relative to 1
  234. doAssert: 0.5 ^ -Inf == Inf
  235. doAssert: -0.5 ^ -Inf == Inf
  236. doAssert: 1.01 ^ -Inf == 0.0
  237. doAssert: -1.01 ^ -Inf == 0.0
  238. doAssert: 0.5 ^ Inf == 0.0
  239. doAssert: -0.5 ^ Inf == 0.0
  240. doAssert: 1.01 ^ Inf == Inf
  241. doAssert: -1.01 ^ Inf == Inf
  242. # -Inf base (the sign depends on the exponent parity)
  243. doAssert: -Inf ^ -5.0 == -0.0
  244. doAssert: -Inf ^ -4.0 == 0.0
  245. doAssert: -Inf ^ -5.1 == 0.0
  246. doAssert: -Inf ^ 3.0 == -Inf
  247. doAssert: -Inf ^ 3.1 == Inf
  248. doAssert: -Inf ^ 2.0 == Inf
  249. doAssert: Inf ^ -5.0 == 0.0
  250. doAssert: Inf ^ -5.1 == 0.0
  251. doAssert: Inf ^ 4.3 == Inf
  252. doAssert: Inf ^ 5.0 == Inf
  253. doAssert: -Inf ^ -Inf == 0.0
  254. doAssert: -Inf ^ Inf == Inf
  255. doAssert: Inf ^ -Inf == 0.0
  256. doAssert: Inf ^ Inf == Inf
  257. block:
  258. # doAssert: 1.0 ^ NaN == 1.0
  259. # doAssert: NaN ^ 0.0 == 1.0
  260. doAssert: (0.0 ^ NaN).isNaN
  261. doAssert: (NaN ^ 1.0).isNaN
  262. block: # isNaN
  263. doAssert NaN.isNaN
  264. doAssert not Inf.isNaN
  265. doAssert isNaN(Inf - Inf)
  266. doAssert not isNaN(0.0)
  267. doAssert not isNaN(3.1415926)
  268. doAssert not isNaN(0'f32)
  269. block: # signbit
  270. doAssert not signbit(0.0)
  271. doAssert signbit(-0.0)
  272. doAssert signbit(-0.1)
  273. doAssert not signbit(0.1)
  274. doAssert not signbit(Inf)
  275. doAssert signbit(-Inf)
  276. doAssert not signbit(NaN)
  277. let x1 = NaN
  278. let x2 = -NaN
  279. let x3 = -x1
  280. doAssert isNaN(x1)
  281. doAssert isNaN(x2)
  282. doAssert isNaN(x3)
  283. doAssert not signbit(x1)
  284. doAssert signbit(x2)
  285. doAssert signbit(x3)
  286. block: # copySign
  287. doAssert copySign(10.0, 1.0) == 10.0
  288. doAssert copySign(10.0, -1.0) == -10.0
  289. doAssert copySign(-10.0, -1.0) == -10.0
  290. doAssert copySign(-10.0, 1.0) == 10.0
  291. doAssert copySign(float(10), -1.0) == -10.0
  292. doAssert copySign(10.0'f64, 1.0) == 10.0
  293. doAssert copySign(10.0'f64, -1.0) == -10.0
  294. doAssert copySign(-10.0'f64, -1.0) == -10.0
  295. doAssert copySign(-10.0'f64, 1.0) == 10.0
  296. doAssert copySign(10'f64, -1.0) == -10.0
  297. doAssert copySign(10.0'f32, 1.0) == 10.0
  298. doAssert copySign(10.0'f32, -1.0) == -10.0
  299. doAssert copySign(-10.0'f32, -1.0) == -10.0
  300. doAssert copySign(-10.0'f32, 1.0) == 10.0
  301. doAssert copySign(10'f32, -1.0) == -10.0
  302. doAssert copySign(Inf, -1.0) == -Inf
  303. doAssert copySign(-Inf, 1.0) == Inf
  304. doAssert copySign(Inf, 1.0) == Inf
  305. doAssert copySign(-Inf, -1.0) == -Inf
  306. doAssert copySign(Inf, 0.0) == Inf
  307. doAssert copySign(Inf, -0.0) == -Inf
  308. doAssert copySign(-Inf, 0.0) == Inf
  309. doAssert copySign(-Inf, -0.0) == -Inf
  310. doAssert copySign(1.0, -0.0) == -1.0
  311. doAssert copySign(0.0, -0.0) == -0.0
  312. doAssert copySign(-1.0, 0.0) == 1.0
  313. doAssert copySign(10.0, 0.0) == 10.0
  314. doAssert copySign(-1.0, NaN) == 1.0
  315. doAssert copySign(10.0, NaN) == 10.0
  316. doAssert copySign(NaN, NaN).isNaN
  317. doAssert copySign(-NaN, NaN).isNaN
  318. doAssert copySign(NaN, -NaN).isNaN
  319. doAssert copySign(-NaN, -NaN).isNaN
  320. doAssert copySign(NaN, 0.0).isNaN
  321. doAssert copySign(NaN, -0.0).isNaN
  322. doAssert copySign(-NaN, 0.0).isNaN
  323. doAssert copySign(-NaN, -0.0).isNaN
  324. doAssert copySign(-1.0, NaN) == 1.0
  325. doAssert copySign(-1.0, -NaN) == -1.0
  326. doAssert copySign(1.0, copySign(NaN, -1.0)) == -1.0
  327. block: # almostEqual
  328. doAssert almostEqual(3.141592653589793, 3.1415926535897936)
  329. doAssert almostEqual(1.6777215e7'f32, 1.6777216e7'f32)
  330. doAssert almostEqual(Inf, Inf)
  331. doAssert almostEqual(-Inf, -Inf)
  332. doAssert not almostEqual(Inf, -Inf)
  333. doAssert not almostEqual(-Inf, Inf)
  334. doAssert not almostEqual(Inf, NaN)
  335. doAssert not almostEqual(NaN, NaN)
  336. block: # round
  337. block: # Round to 0 decimal places
  338. doAssert round(54.652) == 55.0
  339. doAssert round(54.352) == 54.0
  340. doAssert round(-54.652) == -55.0
  341. doAssert round(-54.352) == -54.0
  342. doAssert round(0.0) == 0.0
  343. doAssert 1 / round(0.0) == Inf
  344. doAssert 1 / round(-0.0) == -Inf
  345. doAssert round(Inf) == Inf
  346. doAssert round(-Inf) == -Inf
  347. doAssert round(NaN).isNaN
  348. doAssert round(-NaN).isNaN
  349. doAssert round(-0.5) == -1.0
  350. doAssert round(0.5) == 1.0
  351. doAssert round(-1.5) == -2.0
  352. doAssert round(1.5) == 2.0
  353. doAssert round(-2.5) == -3.0
  354. doAssert round(2.5) == 3.0
  355. doAssert round(2.5'f32) == 3.0'f32
  356. doAssert round(2.5'f64) == 3.0'f64
  357. block: # func round*[T: float32|float64](x: T, places: int): T
  358. doAssert round(54.345, 0) == 54.0
  359. template fn(x) =
  360. doAssert round(x, 2).almostEqual 54.35
  361. doAssert round(x, 2).almostEqual 54.35
  362. doAssert round(x, -1).almostEqual 50.0
  363. doAssert round(x, -2).almostEqual 100.0
  364. doAssert round(x, -3).almostEqual 0.0
  365. fn(54.346)
  366. fn(54.346'f32)
  367. block: # abs
  368. doAssert 1.0 / abs(-0.0) == Inf
  369. doAssert 1.0 / abs(0.0) == Inf
  370. doAssert -1.0 / abs(-0.0) == -Inf
  371. doAssert -1.0 / abs(0.0) == -Inf
  372. doAssert abs(0.0) == 0.0
  373. doAssert abs(0.0'f32) == 0.0'f32
  374. doAssert abs(Inf) == Inf
  375. doAssert abs(-Inf) == Inf
  376. doAssert abs(NaN).isNaN
  377. doAssert abs(-NaN).isNaN
  378. block: # classify
  379. doAssert classify(0.3) == fcNormal
  380. doAssert classify(-0.3) == fcNormal
  381. doAssert classify(5.0e-324) == fcSubnormal
  382. doAssert classify(-5.0e-324) == fcSubnormal
  383. doAssert classify(0.0) == fcZero
  384. doAssert classify(-0.0) == fcNegZero
  385. doAssert classify(NaN) == fcNan
  386. doAssert classify(0.3 / 0.0) == fcInf
  387. doAssert classify(Inf) == fcInf
  388. doAssert classify(-0.3 / 0.0) == fcNegInf
  389. doAssert classify(-Inf) == fcNegInf
  390. block: # sum
  391. let empty: seq[int] = @[]
  392. doAssert sum(empty) == 0
  393. doAssert sum([1, 2, 3, 4]) == 10
  394. doAssert sum([-4, 3, 5]) == 4
  395. block: # prod
  396. let empty: seq[int] = @[]
  397. doAssert prod(empty) == 1
  398. doAssert prod([1, 2, 3, 4]) == 24
  399. doAssert prod([-4, 3, 5]) == -60
  400. doAssert almostEqual(prod([1.5, 3.4]), 5.1)
  401. let x: seq[float] = @[]
  402. doAssert prod(x) == 1.0
  403. block: # clamp range
  404. doAssert clamp(10, 1..5) == 5
  405. doAssert clamp(3, 1..5) == 3
  406. doAssert clamp(5, 1..5) == 5
  407. doAssert clamp(42.0, 1.0 .. 3.1415926535) == 3.1415926535
  408. doAssert clamp(NaN, 1.0 .. 2.0).isNaN
  409. doAssert clamp(-Inf, -Inf .. -1.0) == -Inf
  410. type A = enum a0, a1, a2, a3, a4, a5
  411. doAssert a1.clamp(a2..a4) == a2
  412. doAssert clamp((3, 0), (1, 0) .. (2, 9)) == (2, 9)
  413. block: # edge cases
  414. doAssert sqrt(-4.0).isNaN
  415. doAssert ln(0.0) == -Inf
  416. doAssert ln(-0.0) == -Inf
  417. doAssert ln(-12.0).isNaN
  418. doAssert log10(0.0) == -Inf
  419. doAssert log10(-0.0) == -Inf
  420. doAssert log10(-12.0).isNaN
  421. doAssert log2(0.0) == -Inf
  422. doAssert log2(-0.0) == -Inf
  423. doAssert log2(-12.0).isNaN
  424. when nimvm: discard
  425. else:
  426. doAssert frexp(0.0) == (0.0, 0)
  427. doAssert frexp(-0.0) == (-0.0, 0)
  428. doAssert classify(frexp(-0.0)[0]) == fcNegZero
  429. when not defined(js):
  430. doAssert gamma(0.0) == Inf
  431. doAssert gamma(-0.0) == -Inf
  432. doAssert gamma(-1.0).isNaN
  433. doAssert lgamma(0.0) == Inf
  434. doAssert lgamma(-0.0) == Inf
  435. doAssert lgamma(-1.0) == Inf
  436. static: main()
  437. main()
  438. when not defined(js) and not defined(danger):
  439. block: # bug #21792
  440. block:
  441. type Digit = 0..9
  442. var x = [Digit 4, 7]
  443. doAssertRaises(RangeDefect):
  444. discard sum(x)
  445. block:
  446. var x = [int8 124, 127]
  447. doAssertRaises(OverflowDefect):
  448. discard sum(x)