num-test.scm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. (test-begin "num" 1911)
  2. (define-syntax jequals
  3. (syntax-rules ()
  4. ((jequals x y)
  5. (invoke x 'equals y))))
  6. (define-syntax test-jequals
  7. (syntax-rules ()
  8. ((test-jequals x y)
  9. (test-assert (jequals x y)))))
  10. (test-assert (not (jequals (java.lang.Integer:valueOf 45)
  11. (gnu.math.UInt:valueOf 45))))
  12. (test-assert (not (jequals (java.lang.Integer:valueOf 45)
  13. (gnu.math.IntNum:valueOf 45))))
  14. #|
  15. Not currently true, but perhaps it should be.
  16. (test-assert (not (eqv? (java.lang.Integer:valueOf 45)
  17. (gnu.math.UInt:valueOf 45))))
  18. (test-assert (not (eqv? (java.lang.Integer:valueOf 45)
  19. (gnu.math.IntNum:valueOf 45))))
  20. |#
  21. (test-equal 7 (+ 3 4))
  22. (test-equal 3 (+ 3))
  23. (test-equal 0 (+))
  24. (test-equal +inf.0 (+ +inf.0 +inf.0))
  25. (test-equal +nan.0 (+ +inf.0 -inf.0))
  26. (test-equal 4 (* 4))
  27. (test-equal 1 (*))
  28. (test-equal +inf.0 (* 5 +inf.0))
  29. (test-equal -inf.0 (* -5 +inf.0))
  30. (test-equal +inf.0 (* +inf.0 +inf.0))
  31. (test-equal -inf.0 (* +inf.0 -inf.0))
  32. (test-equal +nan.0 (* 0 +inf.0))
  33. (test-equal +nan.0 (* 0 +nan.0))
  34. (test-equal 0.0 (* 1.0 0))
  35. (test-equal 0.0 (+ 0.0 -0.0))
  36. (test-equal 0.0 (+ -0.0 0.0))
  37. (test-equal 0.0 (+ 0.0 0.0))
  38. (test-equal -0.0 (+ -0.0 -0.0))
  39. (test-equal -1 (- 3 4))
  40. (test-equal -6 (- 3 4 5))
  41. (test-equal -3 (- 3))
  42. (test-equal +nan.0 (- +inf.0 +inf.0))
  43. (test-equal -0.0 (- 0.0))
  44. (test-equal 0.0 (- -0.0))
  45. (test-equal 0.0 (- 0.0 -0.0))
  46. (test-equal -0.0 (- -0.0 0.0))
  47. (test-equal 0.0 (- 0.0 0.0))
  48. (test-equal -1 (- 3 4))
  49. (test-equal -6 (- 3 4 5))
  50. (test-equal -3 (- 3))
  51. (test-equal +nan.0 (- +inf.0 +inf.0))
  52. (test-equal 3/20 (/ 3 4 5))
  53. (test-equal 1/3 (/ 3))
  54. (test-equal +inf.0 (/ 0.0))
  55. (test-equal +inf.0 (/ 1.0 0))
  56. (test-equal -inf.0 (/ -1 0.0))
  57. (test-equal 0.0 (/ +inf.0))
  58. ;(test-error (/ 0 0))
  59. ;(test-error (/ 3 0))
  60. (test-equal 0.0 (/ 0 3.5))
  61. (test-equal +nan.0 (/ 0 0.0))
  62. (test-equal +nan.0 (/ 0.0 0))
  63. (test-equal +nan.0 (/ 0.0 0.0))
  64. (test-equal 12 (div 123 10))
  65. (test-equal -12 (div 123 -10))
  66. (test-equal -13 (div -123 10))
  67. (test-equal 13 (div -123 -10))
  68. (test-equal 3 (mod 123 10))
  69. (test-equal 3 (mod 123 -10))
  70. (test-equal 7 (mod -123 10))
  71. (test-equal 7 (mod -123 -10))
  72. (test-equal 12 (div0 123 10))
  73. (test-equal -12 (div0 123 -10))
  74. (test-equal -12 (div0 -123 10))
  75. (test-equal 12 (div0 -123 -10))
  76. (test-equal 3 (mod0 123 10))
  77. (test-equal 3 (mod0 123 -10))
  78. (test-equal -3 (mod0 -123 10))
  79. (test-equal -3 (mod0 -123 -10))
  80. (test-equal 123 (mod 123 0))
  81. (test-equal -1.0 (remainder -13 -4.0))
  82. (test-equal #(-12 3) (let-values (((r q) (div-and-mod 123 -10)))
  83. (vector r q)))
  84. (test-equal #(-12 -3) (let-values (((x y) (div0-and-mod0 -123 10)))
  85. (vector x y)))
  86. (test-equal 7 (abs -7))
  87. (test-equal +inf.0 (abs -inf.0))
  88. (test-equal 3 (numerator (/ 6 4)))
  89. (test-equal 2 (denominator (/ 6 4)))
  90. (test-equal 1 (denominator 0))
  91. (test-equal -5.0 (floor -4.3))
  92. (test-equal -4.0 (ceiling -4.3))
  93. (test-equal -4.0 (truncate -4.3))
  94. (test-equal -4.0 (round -4.3))
  95. (test-equal 3.0 (floor 3.5))
  96. (test-equal 4.0 (ceiling 3.5))
  97. (test-equal 3.0 (truncate 3.5))
  98. (test-equal 4.0 (round 3.5))
  99. (test-equal 4 (round 7/2))
  100. (test-equal 7 (round 7))
  101. (test-equal +inf.0 (floor +inf.0))
  102. (test-equal -inf.0 (ceiling -inf.0))
  103. (test-equal +nan.0 (round +nan.0))
  104. (test-equal +inf.0 (exp +inf.0))
  105. (test-equal 0.0 (exp -inf.0))
  106. (test-equal +inf.0 (log +inf.0))
  107. (test-equal -inf.0 (log 0.0))
  108. (test-equal +inf.0+3.141592653589793i (log -inf.0)) ; approximately
  109. (test-approximate -1.5707963267948965 (atan -inf.0) 0.00000001)
  110. (test-approximate 1.5707963267948965 (atan +inf.0) 0.00000001)
  111. (test-equal 0.0+3.141592653589793i (log -1.0+0.0i))
  112. (test-equal 0.0-3.141592653589793i (log -1.0-0.0i))
  113. (test-equal 0.0+2.23606797749979i (sqrt -5))
  114. (test-equal +inf.0 (sqrt +inf.0))
  115. (test-equal +inf.0i (sqrt -inf.0))
  116. (test-approximate 1.4 (sqrt 2) 0.02)
  117. (test-error
  118. #t (test-read-eval-string "0.0.0"))
  119. (test-assert
  120. (eq? 3 3))
  121. (test-equal '(2 0) (call-with-values (lambda () (exact-integer-sqrt 4)) list))
  122. (test-equal '(2 1) (call-with-values (lambda () (exact-integer-sqrt 5)) list))
  123. ;; A problem posed by Ken Dickey (kend@data.UUCP) on comp.lang.lisp
  124. ;; to check numerical exactness of Lisp implementations.
  125. (define (dickey-test x y)
  126. (+ (* 1335/4 (expt y 6))
  127. (* (expt x 2)
  128. (- (* 11 (expt x 2) (expt y 2))
  129. (expt y 6)
  130. (* 121 (expt y 4))
  131. 2))
  132. (* 11/2 (expt y 8))
  133. (/ x (* 2 y))))
  134. (test-eqv -54767/66192 (dickey-test 77617 33096))
  135. (test-eqv -1/10000000000000 (/ -1 #e1e13))
  136. (test-eqv 9223372036854775808 (- (- (expt 2 63))))
  137. (test-eqv #i1/0 (+ 1e4294967297))
  138. (test-eqv #i1/0 (* 1e429496729742942949672974967297 1))
  139. (test-eqv 500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  140. (quotient (expt 10 200) (* 20 (expt 10 100))))
  141. (test-eqv
  142. "neg-test" 0 (+ 17280012451545786657095548928 -17280012451545786657095548928))
  143. (test-eqv 1250120440709706990357803482218496
  144. (+ 1250137720722158536144460577767424 -17280012451545786657095548928))
  145. (test-eqv 100000000000000
  146. (quotient 10000000000000000000000000000000000 100000000000000000000))
  147. (test-eqv 1250120440709706990357803482218496
  148. (- 1250137720722158536144460577767424 17280012451545786657095548928))
  149. (test-eqv -1250120440709706990357803482218496
  150. (- 17280012451545786657095548928 1250137720722158536144460577767424))
  151. (test-eqv #t (zero? +0.0))
  152. (test-eqv #t (zero? -0.0))
  153. (test-eqv #f (zero? +nan.0))
  154. (test-eqv #t (positive? +inf.0))
  155. (test-eqv #t (negative? -inf.0))
  156. (test-eqv #f (positive? +nan.0))
  157. (test-eqv #f (negative? +nan.0))
  158. (test-eqv #f (finite? +inf.0))
  159. (test-eqv #t (finite? 5))
  160. (test-eqv #t (finite? 5.0))
  161. (test-eqv #f (infinite? 5.0))
  162. (test-eqv #t (infinite? +inf.0))
  163. (test-group "expt"
  164. (test-eqv 9223372036854775808 (expt 2 63)))
  165. (test-begin "convert")
  166. (test-eqv 10000000000 (inexact->exact (exact->inexact 10000000000)))
  167. (test-eqv 1.4285714285714286e22 (exact->inexact 14285714285714285714285))
  168. (test-eqv 0 (inexact->exact 0.0))
  169. (test-eqv 123451/10 (rationalize (inexact->exact 12345.1) (inexact->exact 0.00001)))
  170. (test-equal 1/3 (rationalize (exact .3) 1/10))
  171. (test-equal #i1/3 (rationalize .3 1/10)) ; approximately
  172. (test-equal +inf.0 (rationalize +inf.0 3))
  173. (test-equal +nan.0 (rationalize +inf.0 +inf.0))
  174. (test-equal 0.0 (rationalize 3 +inf.0))
  175. (test-end "convert")
  176. (test-begin "magnitude")
  177. (test-eqv 4.0( magnitude 4.))
  178. (test-eqv 4e3 (magnitude -4000.))
  179. (test-eqv 5.0 (magnitude 3-4i))
  180. (test-eqv 3/2 (magnitude (/ 6 -4)))
  181. (test-end "magnitude")
  182. (test-begin "shift")
  183. (test-eqv #b1000 (bitwise-arithmetic-shift #b1 3))
  184. (test-eqv #b101 (bitwise-arithmetic-shift #b1010 -1))
  185. (test-eqv 12676506002282294014967032053760 (arithmetic-shift 10 100))
  186. (test-end "shift")
  187. (test-begin "bitwise")
  188. (test-eqv #b1000 (bitwise-and #b1100 #b1010))
  189. (test-eqv #b1110 (bitwise-ior #b1100 #b1010))
  190. (test-eqv #b110 (bitwise-xor #b1100 #b1010))
  191. (test-equal "-10000001" (number->string (lognot #b10000000) 2))
  192. (test-equal "-1" (number->string (lognot #b0) 2))
  193. (test-equal '(-1 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4)
  194. (map bitwise-first-bit-set
  195. '(0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16)))
  196. (test-equal '(-1 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4)
  197. (map bitwise-first-bit-set
  198. '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)))
  199. (test-equal '(#t #f #t #t #f)
  200. (map (lambda (bitno) (bitwise-bit-set? #b1101 bitno)) '(0 1 2 3 4)))
  201. (test-eqv 1 (bitwise-copy-bit 0 0 1))
  202. (test-eqv #b100 (bitwise-copy-bit 0 2 1))
  203. (test-eqv #b1011 (bitwise-copy-bit #b1111 2 0))
  204. (test-eqv #b1010 (bitwise-bit-field #b1101101010 0 4))
  205. (test-eqv #b10110 (bitwise-bit-field #b1101101010 4 9))
  206. (test-eqv #b1101100000 (bitwise-copy-bit-field #b1101101010 0 4 0))
  207. (test-eqv #b1101101111 (bitwise-copy-bit-field #b1101101010 0 4 -1))
  208. (test-eqv #b110100111110000 (bitwise-copy-bit-field #b110100100010000 5 9 -1))
  209. (test-eqv #b10 (bitwise-rotate-bit-field #b0100 0 4 3))
  210. (test-eqv #b10 (bitwise-rotate-bit-field #b0100 0 4 -1)) ;; Extension
  211. (test-eqv #b110100010010000 (bitwise-rotate-bit-field #b110100100010000 5 9 -1))
  212. (test-eqv #b110100000110000 (bitwise-rotate-bit-field #b110100100010000 5 9 1))
  213. (test-eqv #xe5 (bitwise-reverse-bit-field #xa7 0 8))
  214. (test-eqv #xabcdefabcdefabcdefabcdf7
  215. (bitwise-reverse-bit-field #xabcdefabcdefabcdefabcdef 0 8))
  216. (test-eqv #xe013 (bitwise-reverse-bit-field #xf3 5 16))
  217. (test-eqv #xe013aaaaaaaaaaaaaaaa
  218. (bitwise-reverse-bit-field #xf3aaaaaaaaaaaaaaaa 69 80))
  219. (test-end)
  220. (test-begin "logcount/bitwise-count")
  221. (test-eqv 4 (bitwise-bit-count #b10101010))
  222. (test-eqv 0 (bitwise-bit-count 0))
  223. (test-eqv 1 (logcount -2))
  224. (test-eqv -2 (bitwise-bit-count -2))
  225. (test-eqv 3 (logcount 13))
  226. (test-eqv 2 (logcount -13))
  227. (test-eqv 4 (logcount 30))
  228. (test-eqv 4 (logcount -30))
  229. (test-end "logcount/bitwise-count")
  230. (test-begin "gcd")
  231. (test-eqv 3 (gcd 4294967295 3))
  232. (test-eqv 3 (gcd 4294967298 3))
  233. (test-eqv 2874009600 (gcd 1307674368000 2874009600))
  234. (test-end "gcd")
  235. (test-begin "numerical operations")
  236. (test-eqv #t (complex? 3+4i))
  237. (test-eqv #t (complex? 3))
  238. (test-eqv #t (real? 3))
  239. (test-eqv #f (real? -2.5+0.0i))
  240. (test-eqv #t (real? -2.5+0i))
  241. (test-eqv #t (real? -2.5))
  242. (test-eqv #t (real? #e1e10))
  243. (test-eqv #t (rational? 6/10))
  244. (test-eqv #t (rational? 6/3))
  245. (test-eqv #t (rational? 2))
  246. (test-eqv #t (integer? 3+0i))
  247. (test-eqv #t (integer? 3.0))
  248. (test-eqv #t (integer? 8/4))
  249. (test-eqv #t (number? +nan.0))
  250. (test-eqv #t (complex? +nan.0))
  251. (test-eqv #t (real? +nan.0))
  252. (test-eqv #f (rational? +nan.0))
  253. (test-eqv #t (complex? +inf.0))
  254. (test-eqv #t (real? -inf.0))
  255. (test-eqv #f (rational? -inf.0))
  256. (test-eqv #f (integer? -inf.0))
  257. (test-eqv #t (real-valued? +nan.0))
  258. (test-eqv #t (real-valued? +nan.0+0i))
  259. (test-eqv #t (real-valued? -inf.0))
  260. (test-eqv #t (real-valued? 3))
  261. (test-eqv #t (real-valued? -2.5+0.0i))
  262. (test-eqv #t (real-valued? -2.5+0i))
  263. (test-eqv #t (real-valued? -2.5))
  264. (test-eqv #t (real-valued? #e1e10))
  265. (test-eqv #f (rational-valued? +nan.0))
  266. (test-eqv #f (rational-valued? -inf.0))
  267. (test-eqv #t (rational-valued? 6/10))
  268. (test-eqv #t (rational-valued? 6/10+0.0i))
  269. (test-eqv #t (rational-valued? 6/10+0i))
  270. (test-eqv #t (rational-valued? 6/3))
  271. (test-eqv #t (integer-valued? 3+0i))
  272. (test-eqv #t (integer-valued? 3+0.0i))
  273. (test-eqv #t (integer-valued? 3.0))
  274. (test-eqv #t (integer-valued? 3.0+0.0i))
  275. (test-eqv #t (integer-valued? 8/4))
  276. (test-eqv #t (exact? 5))
  277. (test-eqv #t (inexact? +inf.0))
  278. (test-eqv #t (integer? (java.math.BigDecimal "345")))
  279. (test-eqv #f (integer? (java.math.BigDecimal "345.01")))
  280. (test-eqv #t (integer? (java.lang.Long "345")))
  281. (test-eqv #t (integer? (java.lang.Double "345")))
  282. (test-eqv #t (exact-integer? (java.lang.Short "345")))
  283. (test-eqv #f (exact-integer? (java.lang.Double "345")))
  284. (test-eqv #f (exact-integer? (java.math.BigDecimal "345")))
  285. (test-end "numerical operations")
  286. (test-begin "logop")
  287. ;; A Boolean 1-bit version of logop.
  288. (define (logop-bits op x y)
  289. (odd? (quotient op (* (if x 1 4) (if y 1 2)))))
  290. (define (logop-compare result op x y)
  291. (do ((i 0 (+ i 1)))
  292. ((or (= i 100)
  293. (not (eq? (logop-bits op (bitwise-bit-set? x i) (bitwise-bit-set? y i))
  294. (bitwise-bit-set? result i))))
  295. i)
  296. #t))
  297. (define (logop-test1 op x y)
  298. (logop-compare (logop op x y) op x y))
  299. (define test-vals '(0 1 -1 2 -2 3 -3 #x7fffffff
  300. #x-f0f0cccc12345 #x1234567890abcdef0012345))
  301. (define (logop-test op)
  302. (do ((xl test-vals (cdr xl)))
  303. ((null? xl) #t)
  304. (do ((yl test-vals (cdr yl)))
  305. ((null? yl) #t)
  306. (test-eqv 100 (logop-test1 op (car xl) (car yl))))))
  307. (do ((i 0 (+ i 1)))
  308. ((= i 16) #t)
  309. (logop-test i))
  310. (test-end "logop")
  311. (test-group
  312. "integer-length"
  313. (test-eqv 8 (bitwise-length #b10101010))
  314. (test-eqv 4 (bitwise-length #b1111))
  315. (test-eqv 0 (integer-length 0))
  316. (test-eqv 1 (integer-length 1))
  317. (test-eqv 2 (integer-length 3))
  318. (test-eqv 3 (integer-length 4))
  319. (test-eqv 3 (integer-length 7))
  320. (test-eqv 0 (integer-length -1))
  321. (test-eqv 2 (integer-length -4))
  322. (test-eqv 3 (integer-length -7))
  323. (test-eqv 3 (integer-length -8))
  324. (test-eqv 31 (integer-length #x7fffffff))
  325. (test-eqv 32 (integer-length #xffffffff))
  326. (test-eqv 33 (integer-length #x100000000)))
  327. (test-eqv 1000000000000000000000000000000 (* 1000000000000000 1000000000000000))
  328. ;; From Norman Hardy <norm@netcom.com>
  329. (define (ssin x) (let ((a2 (quotient (* x x) dx)))
  330. (- x (let tail ((term x)(ndx 2))
  331. (let ((x (quotient (* a2 term) (* ndx (+ ndx 1) dx))))
  332. (if (zero? x) 0 (- x (tail x (+ ndx 2)))))))))
  333. (define dx (expt 10 100))
  334. (define pi
  335. 31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679)
  336. (test-eqv 3 (ssin pi))
  337. (test-eqv #f (= (expt 2. 100) (+ (expt 2 100) 1)))
  338. (test-eqv #t (= (expt 2. 100) (exact->inexact (+ (expt 2 100) 1))))
  339. (test-eqv 2650239300 (remainder 14853098170650239300 4000000000))
  340. (test-equal "8000000000000000"( number->string #x8000000000000000 16))
  341. (test-equal "80000000000000000"( number->string #x80000000000000000 16))
  342. ;; From Aubrey Jaffer <agj@alum.mit.edu>
  343. (test-eqv #t (number? (string->number "#i0/0+1i")))
  344. (test-eqv #t (number? (string->number "#i1+0/0i")))
  345. (test-eqv #t (positive? 2147483648))
  346. (test-eqv #t (negative? (string->number "#i-1/0")))
  347. (test-eqv 35 (string->number "#36rz"))
  348. (test-eqv 37 (string->number "#36r11"))
  349. ;; From Sven.Hartrumpf@fernuni-hagen.de
  350. (define quotient-fix-1
  351. (lambda (a b x) (quotient (+ (quotient (* a x 10) b) 5) 10)))
  352. (test-eqv 950 (quotient-fix-1 95 100 1000))
  353. ;; Variations on Sven's test:
  354. (define (quotient-fix-2 (a :: <real>))
  355. (quotient (+ a 20) 10))
  356. (test-eqv 97 (quotient-fix-2 950))
  357. (define (quotient-float (a :: <real>))
  358. (quotient (+ a 25.0) 10))
  359. (test-eqv 97.0 (quotient-float 950))
  360. (define v (vector 3 -4/5 9 10 (+ 8 1/2) -100))
  361. (java.util.Collections:sort v)
  362. (test-equal "sort-v-1" #(-100 -4/5 3 17/2 9 10) v)
  363. (set! v (vector 1.2 -1.2 8.9 100.0 8.9))
  364. (java.util.Collections:sort v)
  365. (test-equal "sort-v-2" #(-1.2 1.2 8.9 8.9 100.0) v)
  366. (set! v (vector 1 0.5 5/2 8 2.5))
  367. (java.util.Collections:sort v)
  368. (test-equal "sort-v-3" #(0.5 1 5/2 2.5 8) v)
  369. (set! v (vector "abc" "aa" "zy" ""))
  370. (java.util.Collections:sort v)
  371. (test-equal "sort-v-4" #("" "aa" "abc" "zy") v)
  372. (set! v (f32vector 1.2 -1.2 8.9 100.0 8.9))
  373. (java.util.Collections:sort v)
  374. (test-equal "sort-v-5" #f32(-1.2 1.2 8.9 8.9 100.0) v)
  375. (set! v (vector #s64(3 5) #s64(3 4 5) #s64(-1) #s64(-5)
  376. #s64(-1 20) #s64() #s64(-1 10)))
  377. (java.util.Collections:sort v)
  378. (test-equal
  379. "sort-v-6"
  380. #(#s64() #s64(-5) #s64(-1) #s64(-1 10) #s64(-1 20) #s64(3 4 5) #s64(3 5))
  381. v)
  382. (set! v '("abc" "aa" "zy" ""))
  383. (java.util.Collections:sort v)
  384. (test-assert "sort-v-7" (equal? '("" "aa" "abc" "zy") v))
  385. (set! v (vector '(b 3) '(a 1) '(b 2) '(a 2) '(b -1) '(a)))
  386. (java.util.Collections:sort v)
  387. (test-equal "sort-v-8" #((a) (a 1) (a 2) (b -1) (b 2) (b 3)) v)
  388. ;; Savannah bug #11427 Dean Ferreyra <dferreyra@igc.org>
  389. ;; <java.lang.Integer> in the interpreter gives ClassCastException.
  390. (define seven (make <java.lang.Integer> 7))(- (as <int> seven) 3)
  391. (test-assert (= seven 7))
  392. ;; Bug reported by Alex Mitchell
  393. (define denom 10.0)
  394. (test-equal 0.0 (let ((numer2 0)) (/ numer2 denom)))
  395. ;; Bug reported by Alex Mitchell
  396. (test-equal '(20.0) (let ((b (* denom 2.0))) (list b)))
  397. (test-equal "java.lang.Float" (invoke (invoke 12.5s2 'getClass) 'getName))
  398. (test-equal "java.lang.Float" (invoke (invoke 12.5F2 'getClass) 'getName))
  399. (test-equal "java.lang.Double" (invoke (invoke 12.5d2 'getClass) 'getName))
  400. (test-equal "java.math.BigDecimal" (invoke (invoke 12.5l2 'getClass) 'getName))
  401. (test-equal "gnu.math.DFloNum" (invoke (invoke 12.5e2 'getClass) 'getName))
  402. (test-equal "gnu.math.DFloNum" (invoke (invoke 12.5 'getClass) 'getName))
  403. (test-assert (= 0.0s0 0.0s0))
  404. (test-assert (eqv? 0.0s0 0.0s0))
  405. (test-assert (equal? 0.0s0 0.0s0))
  406. (test-assert (= 0.0s0 0.0d0))
  407. (test-eqv #f (eqv? 0.0s0 0.0d0))
  408. (test-eqv #f (equal? 0.0s0 0.0d0))
  409. (test-assert (= java.lang.Double:POSITIVE_INFINITY
  410. java.lang.Float:POSITIVE_INFINITY))
  411. (test-eqv #f (equal? java.lang.Double:POSITIVE_INFINITY
  412. java.lang.Float:POSITIVE_INFINITY))
  413. (test-assert (> 1/0 -1/0))
  414. (test-assert (< -1/0 1/0))
  415. (test-assert (> 4/5 -1/0))
  416. (test-assert (< 4/5 1/0))
  417. (test-assert (< 0 1/0))
  418. (test-assert (> 4.5 -1/0))
  419. (define (circle-area radius) (* java.lang.Math:PI (expt radius 2)))
  420. (test-approximate 28.27 (circle-area 3) 0.1)
  421. (test-assert (not (gnu.math.Complex:equals 3+4i 3+5i)))
  422. (require <InliningTest>)
  423. (for-each (lambda (vals)
  424. (let (([x y r] vals))
  425. (test-equal r (greater-equal-u32-s32 x y))
  426. (test-equal r (greater-equal-u32-s32-generic x y))))
  427. '((#xffffffff 3 #t)
  428. (#xfffffffc #x7fffffff #t)
  429. (#xfffffffc #xffffffff #t)
  430. (#x7ffffffc #x7fffffff #f)
  431. (#xffffffff -3 #t)))
  432. (for-each (lambda (vals)
  433. (let (([x y r] vals))
  434. (test-equal r (greater-equal-u64-u64 x y))
  435. (test-equal r (greater-equal-u64-u64-generic x y))))
  436. '((#xffffffffffffffff 3 #t)
  437. (#xfffffffffffffffA #xfffffffffffffffC #f)))
  438. (test-equal 65586 (add-u8a-u16a))
  439. ;; To avoid inlining, use a wrapper function.
  440. (define (my-ashift x y::int) (arithmetic-shift x y))
  441. (test-jequals (->uint #xf80000A8) (my-ashift (->uint #xFF000015) 3))
  442. (test-jequals (->uint #x1fe00002) (my-ashift (->uint #xFF000015) -3))
  443. (test-jequals (->int -134217560) (my-ashift (->int (->uint #xFF000015)) 3))
  444. (test-jequals (->int -2097150) (my-ashift (->int (->uint #xFF000015)) -3))
  445. (test-equal (->int 253) (->int (index-u8v1 1)))
  446. (test-equal (->int 253) (->int (index-u8i1 1)))
  447. (test-equal (->int 253) (->int (index-u8i2 1)))
  448. (define u32x ::uint #xFFFFFFF0)
  449. (test-assert (= u32x #xFFFFFFF0))
  450. (test-assert (= u32x (+ (->uint #xFFFFFFE8) 8)))
  451. (let* ((vec1 ::dynamic (u32vector 4 5 6 7)))
  452. (set! (vec1 2) u32x)
  453. (test-equal u32x (vec1 2))
  454. (test-equal 7 (vec1 3)))
  455. (test-end)