numbers.test 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. ;;;; numbers.test --- tests guile's numbers -*- scheme -*-
  2. ;;;; Copyright (C) 2000 Free Software Foundation, Inc.
  3. ;;;;
  4. ;;;; This program is free software; you can redistribute it and/or modify
  5. ;;;; it under the terms of the GNU General Public License as published by
  6. ;;;; the Free Software Foundation; either version 2, or (at your option)
  7. ;;;; any later version.
  8. ;;;;
  9. ;;;; This program is distributed in the hope that it will be useful,
  10. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;;;; GNU General Public License for more details.
  13. ;;;;
  14. ;;;; You should have received a copy of the GNU General Public License
  15. ;;;; along with this software; see the file COPYING. If not, write to
  16. ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. ;;;; Boston, MA 02111-1307 USA
  18. ;;;;
  19. ;;;; As a special exception, the Free Software Foundation gives permission
  20. ;;;; for additional uses of the text contained in its release of GUILE.
  21. ;;;;
  22. ;;;; The exception is that, if you link the GUILE library with other files
  23. ;;;; to produce an executable, this does not by itself cause the
  24. ;;;; resulting executable to be covered by the GNU General Public License.
  25. ;;;; Your use of that executable is in no way restricted on account of
  26. ;;;; linking the GUILE library code into it.
  27. ;;;;
  28. ;;;; This exception does not however invalidate any other reasons why
  29. ;;;; the executable file might be covered by the GNU General Public License.
  30. ;;;;
  31. ;;;; This exception applies only to the code released by the
  32. ;;;; Free Software Foundation under the name GUILE. If you copy
  33. ;;;; code from other Free Software Foundation releases into a copy of
  34. ;;;; GUILE, as the General Public License permits, the exception does
  35. ;;;; not apply to the code that you add in this way. To avoid misleading
  36. ;;;; anyone as to the status of such modified files, you must delete
  37. ;;;; this exception notice from them.
  38. ;;;;
  39. ;;;; If you write modifications of your own for GUILE, it is your choice
  40. ;;;; whether to permit this exception to apply to your modifications.
  41. ;;;; If you do not wish that, delete this exception notice.
  42. (use-modules (ice-9 documentation))
  43. ;;;
  44. ;;; miscellaneous
  45. ;;;
  46. (define (documented? object)
  47. (object-documentation object))
  48. (define (make-test-name . args)
  49. (with-output-to-string
  50. (lambda ()
  51. (for-each display args))))
  52. (define bit-widths '(8 16 27 28 29 30 31 32 64 128 256))
  53. (define (2^x-1 x)
  54. (- (expt 2 x) 1))
  55. (define (2^ x)
  56. (expt 2 x))
  57. (define (n=2^x-1 x)
  58. (make-test-name "n = 2^" x " - 1"))
  59. (define (n=-2^x+1 x)
  60. (make-test-name "n = -2^" x " + 1"))
  61. (define (n=2^ x)
  62. (make-test-name "n = 2^" x))
  63. (define (n=-2^ x)
  64. (make-test-name "n = -2^" x))
  65. ;;;
  66. ;;; exact?
  67. ;;;
  68. (with-test-prefix "exact?"
  69. ;; Is documentation available?
  70. (pass-if "documented?"
  71. (documented? exact?))
  72. ;; Special case: 0
  73. (pass-if "0"
  74. (eq? #t (exact? 0)))
  75. ;; integers:
  76. (for-each
  77. (lambda (x)
  78. (pass-if (make-test-name "2^" x " - 1")
  79. (eq? #t (exact? (2^x-1 x))))
  80. (pass-if (make-test-name "-2^" x " + 1")
  81. (eq? #t (exact? (- (2^x-1 x)))))
  82. (pass-if (make-test-name "2^" x)
  83. (eq? #t (exact? (2^ x))))
  84. (pass-if (make-test-name "-2^" x)
  85. (eq? #t (exact? (- (2^ x))))))
  86. bit-widths)
  87. ;; floats: (FIXME: need more examples)
  88. (for-each
  89. (lambda (x)
  90. (pass-if (make-test-name "sqrt((2^" x " - 1)^2 - 1)")
  91. (eq? #f (exact? (sqrt (- (* (2^x-1 x) (2^x-1 x)) 1)))))
  92. (pass-if (make-test-name "sqrt((2^" x ")^2 + 1)")
  93. (eq? #f (exact? (sqrt (+ (* (2^ x) (2^ x)) 1))))))
  94. bit-widths))
  95. ;;;
  96. ;;; odd?
  97. ;;;
  98. ;;;
  99. ;;; even?
  100. ;;;
  101. ;;;
  102. ;;; abs
  103. ;;;
  104. ;;;
  105. ;;; quotient
  106. ;;;
  107. (with-test-prefix "quotient"
  108. ;; Is documentation available?
  109. (expect-fail "documented?"
  110. (documented? quotient))
  111. ;; Special case: 0 / n
  112. (with-test-prefix "0 / n"
  113. (pass-if "n = 1"
  114. (eqv? 0 (quotient 0 1)))
  115. (pass-if "n = -1"
  116. (eqv? 0 (quotient 0 -1)))
  117. (for-each
  118. (lambda (x)
  119. (pass-if (n=2^x-1 x)
  120. (eqv? 0 (quotient 0 (2^x-1 x))))
  121. (pass-if (n=-2^x+1 x)
  122. (eqv? 0 (quotient 0 (- (2^x-1 x)))))
  123. (pass-if (n=2^ x)
  124. (eqv? 0 (quotient 0 (expt 2 x))))
  125. (pass-if (n=-2^ x)
  126. (eqv? 0 (quotient 0 (- (expt 2 x))))))
  127. bit-widths))
  128. ;; Special case: n / 1
  129. (with-test-prefix "n / 1"
  130. (pass-if "n = 1"
  131. (eqv? 1 (quotient 1 1)))
  132. (pass-if "n = -1"
  133. (eqv? -1 (quotient -1 1)))
  134. (for-each
  135. (lambda (x)
  136. (pass-if (n=2^x-1 x)
  137. (eqv? (2^x-1 x) (quotient (2^x-1 x) 1)))
  138. (pass-if (n=-2^x+1 x)
  139. (eqv? (- (2^x-1 x)) (quotient (- (2^x-1 x)) 1)))
  140. (pass-if (n=2^ x)
  141. (eqv? (2^ x) (quotient (2^ x) 1)))
  142. (pass-if (n=-2^ x)
  143. (eqv? (- (2^ x)) (quotient (- (2^ x)) 1))))
  144. bit-widths))
  145. ;; Special case: n / -1
  146. (with-test-prefix "n / -1"
  147. (pass-if "n = 1"
  148. (eqv? -1 (quotient 1 -1)))
  149. (pass-if "n = -1"
  150. (eqv? 1 (quotient -1 -1)))
  151. (for-each
  152. (lambda (x)
  153. (pass-if (n=2^x-1 x)
  154. (eqv? (- (2^x-1 x)) (quotient (2^x-1 x) -1)))
  155. (pass-if (n=-2^x+1 x)
  156. (eqv? (2^x-1 x) (quotient (- (2^x-1 x)) -1)))
  157. (pass-if (n=2^ x)
  158. (eqv? (- (2^ x)) (quotient (2^ x) -1)))
  159. (pass-if (n=-2^ x)
  160. (eqv? (2^ x) (quotient (- (2^ x)) -1))))
  161. bit-widths))
  162. ;; Special case: n / n
  163. (with-test-prefix "n / n"
  164. (for-each
  165. (lambda (x)
  166. (pass-if (n=2^x-1 x)
  167. (eqv? 1 (quotient (2^x-1 x) (2^x-1 x))))
  168. (pass-if (n=-2^x+1 x)
  169. (eqv? 1 (quotient (- (2^x-1 x)) (- (2^x-1 x)))))
  170. (pass-if (n=2^ x)
  171. (eqv? 1 (quotient (2^ x) (2^ x))))
  172. (pass-if (n=-2^ x)
  173. (eqv? 1 (quotient (- (2^ x)) (- (2^ x))))))
  174. bit-widths))
  175. ;; Positive dividend and divisor
  176. (pass-if "35 / 7"
  177. (eqv? 5 (quotient 35 7)))
  178. ;; Negative dividend, positive divisor
  179. (pass-if "-35 / 7"
  180. (eqv? -5 (quotient -35 7)))
  181. ;; Positive dividend, negative divisor
  182. (pass-if "35 / -7"
  183. (eqv? -5 (quotient 35 -7)))
  184. ;; Negative dividend and divisor
  185. (pass-if "-35 / -7"
  186. (eqv? 5 (quotient -35 -7)))
  187. ;; Are numerical overflows detected correctly?
  188. ;; Are wrong type arguments detected correctly?
  189. )
  190. ;;;
  191. ;;; remainder
  192. ;;;
  193. (with-test-prefix "remainder"
  194. ;; Is documentation available?
  195. (expect-fail "documented?"
  196. (documented? remainder))
  197. ;; Special case: 0 / n
  198. (with-test-prefix "0 / n"
  199. (pass-if "n = 1"
  200. (eqv? 0 (remainder 0 1)))
  201. (pass-if "n = -1"
  202. (eqv? 0 (remainder 0 -1)))
  203. (for-each
  204. (lambda (x)
  205. (pass-if (n=2^x-1 x)
  206. (eqv? 0 (remainder 0 (2^x-1 x))))
  207. (pass-if (n=-2^x+1 x)
  208. (eqv? 0 (remainder 0 (- (2^x-1 x)))))
  209. (pass-if (n=2^ x)
  210. (eqv? 0 (remainder 0 (2^ x))))
  211. (pass-if (n=-2^ x)
  212. (eqv? 0 (remainder 0 (- (2^ x))))))
  213. bit-widths))
  214. ;; Special case: n / 1
  215. (with-test-prefix "n / 1"
  216. (pass-if "n = 1"
  217. (eqv? 0 (remainder 1 1)))
  218. (pass-if "n = -1"
  219. (eqv? 0 (remainder -1 1)))
  220. (for-each
  221. (lambda (x)
  222. (pass-if (n=2^x-1 x)
  223. (eqv? 0 (remainder (2^x-1 x) 1)))
  224. (pass-if (n=-2^x+1 x)
  225. (eqv? 0 (remainder (- (2^x-1 x)) 1)))
  226. (pass-if (n=2^ x)
  227. (eqv? 0 (remainder (2^ x) 1)))
  228. (pass-if (n=-2^ x)
  229. (eqv? 0 (remainder (- (2^ x)) 1))))
  230. bit-widths))
  231. ;; Special case: n / -1
  232. (with-test-prefix "n / -1"
  233. (pass-if "n = 1"
  234. (eqv? 0 (remainder 1 -1)))
  235. (pass-if "n = -1"
  236. (eqv? 0 (remainder -1 -1)))
  237. (for-each
  238. (lambda (x)
  239. (pass-if (n=2^x-1 x)
  240. (eqv? 0 (remainder (2^x-1 x) -1)))
  241. (pass-if (n=-2^x+1 x)
  242. (eqv? 0 (remainder (- (2^x-1 x)) -1)))
  243. (pass-if (n=2^ x)
  244. (eqv? 0 (remainder (2^ x) -1)))
  245. (pass-if (n=-2^ x)
  246. (eqv? 0 (remainder (- (2^ x)) -1))))
  247. bit-widths))
  248. ;; Special case: n / n
  249. (with-test-prefix "n / n"
  250. (for-each
  251. (lambda (x)
  252. (pass-if (n=2^x-1 x)
  253. (eqv? 0 (remainder (2^x-1 x) (2^x-1 x))))
  254. (pass-if (n=-2^x+1 x)
  255. (eqv? 0 (remainder (- (2^x-1 x)) (- (2^x-1 x)))))
  256. (pass-if (n=2^ x)
  257. (eqv? 0 (remainder (2^ x) (2^ x))))
  258. (pass-if (n=-2^ x)
  259. (eqv? 0 (remainder (- (2^ x)) (- (2^ x))))))
  260. bit-widths))
  261. ;; Positive dividend and divisor
  262. (pass-if "35 / 7"
  263. (eqv? 0 (remainder 35 7)))
  264. ;; Negative dividend, positive divisor
  265. (pass-if "-35 / 7"
  266. (eqv? 0 (remainder -35 7)))
  267. ;; Positive dividend, negative divisor
  268. (pass-if "35 / -7"
  269. (eqv? 0 (remainder 35 -7)))
  270. ;; Negative dividend and divisor
  271. (pass-if "-35 / -7"
  272. (eqv? 0 (remainder -35 -7)))
  273. ;; Are numerical overflows detected correctly?
  274. ;; Are wrong type arguments detected correctly?
  275. )
  276. ;;;
  277. ;;; modulo
  278. ;;;
  279. (with-test-prefix "modulo"
  280. ;; Is documentation available?
  281. (expect-fail "documented?"
  282. (documented? modulo))
  283. ;; Special case: 0 % n
  284. (with-test-prefix "0 % n"
  285. (pass-if "n = 1"
  286. (eqv? 0 (modulo 0 1)))
  287. (pass-if "n = -1"
  288. (eqv? 0 (modulo 0 -1)))
  289. (for-each
  290. (lambda (x)
  291. (pass-if (n=2^x-1 x)
  292. (eqv? 0 (modulo 0 (2^x-1 x))))
  293. (pass-if (n=-2^x+1 x)
  294. (eqv? 0 (modulo 0 (- (2^x-1 x)))))
  295. (pass-if (n=2^ x)
  296. (eqv? 0 (modulo 0 (2^ x))))
  297. (pass-if (n=-2^ x)
  298. (eqv? 0 (modulo 0 (- (2^ x))))))
  299. bit-widths))
  300. ;; Special case: n % 1
  301. (with-test-prefix "n % 1"
  302. (pass-if "n = 1"
  303. (eqv? 0 (modulo 1 1)))
  304. (pass-if "n = -1"
  305. (eqv? 0 (modulo -1 1)))
  306. (for-each
  307. (lambda (x)
  308. (pass-if (n=2^x-1 x)
  309. (eqv? 0 (modulo (2^x-1 x) 1)))
  310. (pass-if (n=-2^x+1 x)
  311. (eqv? 0 (modulo (- (2^x-1 x)) 1)))
  312. (pass-if (n=2^ x)
  313. (eqv? 0 (modulo (2^ x) 1)))
  314. (pass-if (n=-2^ x)
  315. (eqv? 0 (modulo (- (2^ x)) 1))))
  316. bit-widths))
  317. ;; Special case: n % -1
  318. (with-test-prefix "n % -1"
  319. (pass-if "n = 1"
  320. (eqv? 0 (modulo 1 -1)))
  321. (pass-if "n = -1"
  322. (eqv? 0 (modulo -1 -1)))
  323. (for-each
  324. (lambda (x)
  325. (pass-if (n=2^x-1 x)
  326. (eqv? 0 (modulo (2^x-1 x) -1)))
  327. (pass-if (n=-2^x+1 x)
  328. (eqv? 0 (modulo (- (2^x-1 x)) -1)))
  329. (pass-if (n=2^ x)
  330. (eqv? 0 (modulo (2^ x) -1)))
  331. (pass-if (n=-2^ x)
  332. (eqv? 0 (modulo (- (2^ x)) -1))))
  333. bit-widths))
  334. ;; Special case: n % n
  335. (with-test-prefix "n % n"
  336. (for-each
  337. (lambda (x)
  338. (pass-if (n=2^x-1 x)
  339. (eqv? 0 (modulo (2^x-1 x) (2^x-1 x))))
  340. (pass-if (n=-2^x+1 x)
  341. (eqv? 0 (modulo (- (2^x-1 x)) (- (2^x-1 x)))))
  342. (pass-if (n=2^ x)
  343. (eqv? 0 (modulo (2^ x) (2^ x))))
  344. (pass-if (n=-2^ x)
  345. (eqv? 0 (modulo (- (2^ x)) (- (2^ x))))))
  346. bit-widths))
  347. ;; Positive dividend and divisor
  348. (pass-if "13 % 4"
  349. (eqv? 1 (modulo 13 4)))
  350. (pass-if "2177452800 % 86400"
  351. (eqv? 0 (modulo 2177452800 86400)))
  352. ;; Negative dividend, positive divisor
  353. (pass-if "-13 % 4"
  354. (eqv? 3 (modulo -13 4)))
  355. (pass-if "-2177452800 % 86400"
  356. (eqv? 0 (modulo -2177452800 86400)))
  357. ;; Positive dividend, negative divisor
  358. (pass-if "13 % -4"
  359. (eqv? -3 (modulo 13 -4)))
  360. (pass-if "2177452800 % -86400"
  361. (eqv? 0 (modulo 2177452800 -86400)))
  362. ;; Negative dividend and divisor
  363. (pass-if "-13 % -4"
  364. (eqv? -1 (modulo -13 -4)))
  365. (pass-if "-2177452800 % -86400"
  366. (eqv? 0 (modulo -2177452800 -86400)))
  367. ;; Are numerical overflows detected correctly?
  368. ;; Are wrong type arguments detected correctly?
  369. )
  370. ;;;
  371. ;;; gcd
  372. ;;;
  373. (with-test-prefix "gcd"
  374. ;; Is documentation available?
  375. (expect-fail "documented?"
  376. (documented? gcd))
  377. ;; Special case: gcd 0 n
  378. (with-test-prefix "(0 n)"
  379. (pass-if "n = 1"
  380. (eqv? 1 (gcd 0 1)))
  381. (pass-if "n = -1"
  382. (eqv? 1 (gcd 0 -1)))
  383. (for-each
  384. (lambda (x)
  385. (pass-if (n=2^x-1 x)
  386. (eqv? (2^x-1 x) (gcd 0 (2^x-1 x))))
  387. (pass-if (n=-2^x+1 x)
  388. (eqv? (2^x-1 x) (gcd 0 (- (2^x-1 x)))))
  389. (pass-if (n=2^ x)
  390. (eqv? (2^ x) (gcd 0 (2^ x))))
  391. (pass-if (n=-2^ x)
  392. (eqv? (2^ x) (gcd 0 (- (2^ x))))))
  393. bit-widths))
  394. ;; Special case: gcd n 0
  395. (with-test-prefix "(n 0)"
  396. (pass-if "n = 1"
  397. (eqv? 1 (gcd 1 0)))
  398. (pass-if "n = -1"
  399. (eqv? 1 (gcd -1 0)))
  400. (for-each
  401. (lambda (x)
  402. (pass-if (n=2^x-1 x)
  403. (eqv? (2^x-1 x) (gcd (2^x-1 x) 0)))
  404. (pass-if (n=-2^x+1 x)
  405. (eqv? (2^x-1 x) (gcd (- (2^x-1 x)) 0)))
  406. (pass-if (n=2^ x)
  407. (eqv? (2^ x) (gcd (2^ x) 0)))
  408. (pass-if (n=-2^ x)
  409. (eqv? (2^ x) (gcd (- (2^ x)) 0))))
  410. bit-widths))
  411. ;; Special case: gcd 1 n
  412. (with-test-prefix "(1 n)"
  413. (pass-if "n = 1"
  414. (eqv? 1 (gcd 1 1)))
  415. (pass-if "n = -1"
  416. (eqv? 1 (gcd 1 -1)))
  417. (for-each
  418. (lambda (x)
  419. (pass-if (n=2^x-1 x)
  420. (eqv? 1 (gcd 1 (2^x-1 x))))
  421. (pass-if (n=-2^x+1 x)
  422. (eqv? 1 (gcd 1 (- (2^x-1 x)))))
  423. (pass-if (n=2^ x)
  424. (eqv? 1 (gcd 1 (2^ x))))
  425. (pass-if (n=-2^ x)
  426. (eqv? 1 (gcd 1 (- (2^ x))))))
  427. bit-widths))
  428. ;; Special case: gcd n 1
  429. (with-test-prefix "(n 1)"
  430. (pass-if "n = -1"
  431. (eqv? 1 (gcd -1 1)))
  432. (for-each
  433. (lambda (x)
  434. (pass-if (n=2^x-1 x)
  435. (eqv? 1 (gcd (2^x-1 x) 1)))
  436. (pass-if (n=-2^x+1 x)
  437. (eqv? 1 (gcd (- (2^x-1 x)) 1)))
  438. (pass-if (n=2^ x)
  439. (eqv? 1 (gcd (2^ x) 1)))
  440. (pass-if (n=-2^ x)
  441. (eqv? 1 (gcd (- (2^ x)) 1))))
  442. bit-widths))
  443. ;; Special case: gcd -1 n
  444. (with-test-prefix "(-1 n)"
  445. (pass-if "n = -1"
  446. (eqv? 1 (gcd -1 -1)))
  447. (for-each
  448. (lambda (x)
  449. (pass-if (n=2^x-1 x)
  450. (eqv? 1 (gcd -1 (2^x-1 x))))
  451. (pass-if (n=-2^x+1 x)
  452. (eqv? 1 (gcd -1 (- (2^x-1 x)))))
  453. (pass-if (n=2^ x)
  454. (eqv? 1 (gcd -1 (2^ x))))
  455. (pass-if (n=-2^ x)
  456. (eqv? 1 (gcd -1 (- (2^ x))))))
  457. bit-widths))
  458. ;; Special case: gcd n -1
  459. (with-test-prefix "(n -1)"
  460. (for-each
  461. (lambda (x)
  462. (pass-if (n=2^x-1 x)
  463. (eqv? 1 (gcd (2^x-1 x) -1)))
  464. (pass-if (n=-2^x+1 x)
  465. (eqv? 1 (gcd (- (2^x-1 x)) -1)))
  466. (pass-if (n=2^ x)
  467. (eqv? 1 (gcd (2^ x) -1)))
  468. (pass-if (n=-2^ x)
  469. (eqv? 1 (gcd (- (2^ x)) -1))))
  470. bit-widths))
  471. ;; Special case: gcd n n
  472. (with-test-prefix "(n n)"
  473. (for-each
  474. (lambda (x)
  475. (pass-if (n=2^x-1 x)
  476. (eqv? (2^x-1 x) (gcd (2^x-1 x) (2^x-1 x))))
  477. (pass-if (n=-2^x+1 x)
  478. (eqv? (2^x-1 x) (gcd (- (2^x-1 x)) (- (2^x-1 x)))))
  479. (pass-if (n=2^ x)
  480. (eqv? (2^ x) (gcd (2^ x) (2^ x))))
  481. (pass-if (n=-2^ x)
  482. (eqv? (2^ x) (gcd (- (2^ x)) (- (2^ x))))))
  483. bit-widths))
  484. ;; Are wrong type arguments detected correctly?
  485. )
  486. ;;;
  487. ;;; <
  488. ;;;
  489. (with-test-prefix "<"
  490. ;; Is documentation available?
  491. (expect-fail "documented?"
  492. (documented? <))
  493. ;; Special case: 0 < n
  494. (with-test-prefix "(< 0 n)"
  495. (pass-if "n = 0"
  496. (not (< 0 0)))
  497. (pass-if "n = 0.0"
  498. (not (< 0 0.0)))
  499. (pass-if "n = 1"
  500. (< 0 1))
  501. (pass-if "n = 1.0"
  502. (< 0 1.0))
  503. (pass-if "n = -1"
  504. (not (< 0 -1)))
  505. (pass-if "n = -1.0"
  506. (not (< 0 -1.0)))
  507. (for-each ;; FIXME: compare agains floats.
  508. (lambda (x)
  509. (pass-if (n=2^x-1 x)
  510. (< 0 (2^x-1 x)))
  511. (pass-if (n=-2^x+1 x)
  512. (not (< 0 (- (2^x-1 x)))))
  513. (pass-if (n=2^ x)
  514. (< 0 (2^ x)))
  515. (pass-if (n=-2^ x)
  516. (not (< 0 (- (2^ x))))))
  517. bit-widths))
  518. ;; Special case: 0.0 < n
  519. (with-test-prefix "(< 0.0 n)"
  520. (pass-if "n = 0"
  521. (not (< 0.0 0)))
  522. (pass-if "n = 0.0"
  523. (not (< 0.0 0.0)))
  524. (pass-if "n = 1"
  525. (< 0.0 1))
  526. (pass-if "n = 1.0"
  527. (< 0.0 1.0))
  528. (pass-if "n = -1"
  529. (not (< 0.0 -1)))
  530. (pass-if "n = -1.0"
  531. (not (< 0.0 -1.0)))
  532. (for-each ;; FIXME: compare agains floats.
  533. (lambda (x)
  534. (pass-if (n=2^x-1 x)
  535. (< 0.0 (2^x-1 x)))
  536. (pass-if (n=-2^x+1 x)
  537. (not (< 0.0 (- (2^x-1 x)))))
  538. (pass-if (n=2^ x)
  539. (< 0.0 (2^ x)))
  540. (pass-if (n=-2^ x)
  541. (not (< 0.0 (- (2^ x))))))
  542. bit-widths))
  543. ;; Special case: n < 0
  544. (with-test-prefix "(< n 0)"
  545. (pass-if "n = 1"
  546. (not (< 1 0)))
  547. (pass-if "n = 1.0"
  548. (not (< 1.0 0)))
  549. (pass-if "n = -1"
  550. (< -1 0))
  551. (pass-if "n = -1.0"
  552. (< -1.0 0))
  553. (for-each ;; FIXME: compare agains floats.
  554. (lambda (x)
  555. (pass-if (n=2^x-1 x)
  556. (not (< (2^x-1 x) 0)))
  557. (pass-if (n=-2^x+1 x)
  558. (< (- (2^x-1 x)) 0))
  559. (pass-if (n=2^ x)
  560. (not (< (2^ x) 0)))
  561. (pass-if (n=-2^ x)
  562. (< (- (2^ x)) 0)))
  563. bit-widths))
  564. ;; Special case: n < 0.0
  565. (with-test-prefix "(< n 0.0)"
  566. (pass-if "n = 1"
  567. (not (< 1 0.0)))
  568. (pass-if "n = 1.0"
  569. (not (< 1.0 0.0)))
  570. (pass-if "n = -1"
  571. (< -1 0.0))
  572. (pass-if "n = -1.0"
  573. (< -1.0 0.0))
  574. (for-each ;; FIXME: compare agains floats.
  575. (lambda (x)
  576. (pass-if (n=2^x-1 x)
  577. (not (< (2^x-1 x) 0.0)))
  578. (pass-if (n=-2^x+1 x)
  579. (< (- (2^x-1 x)) 0.0))
  580. (pass-if (n=2^ x)
  581. (not (< (2^ x) 0.0)))
  582. (pass-if (n=-2^ x)
  583. (< (- (2^ x)) 0.0)))
  584. bit-widths))
  585. ;; Special case: n < n
  586. (with-test-prefix "(< n n)"
  587. (pass-if "n = 1"
  588. (not (< 1 1)))
  589. (pass-if "n = 1.0"
  590. (not (< 1.0 1.0)))
  591. (pass-if "n = -1"
  592. (not (< -1 -1)))
  593. (pass-if "n = -1.0"
  594. (not (< -1.0 -1.0)))
  595. (for-each ;; FIXME: compare agains floats.
  596. (lambda (x)
  597. (pass-if (n=2^x-1 x)
  598. (not (< (2^x-1 x) (2^x-1 x))))
  599. (pass-if (n=-2^x+1 x)
  600. (not (< (- (2^x-1 x)) (- (2^x-1 x)))))
  601. (pass-if (n=2^ x)
  602. (not (< (2^ x) (2^ x))))
  603. (pass-if (n=-2^ x)
  604. (not (< (- (2^ x)) (- (2^ x))))))
  605. bit-widths))
  606. ;; Special case: n < n + 1
  607. (with-test-prefix "(< n (+ n 1))"
  608. (pass-if "n = 1"
  609. (< 1 2))
  610. (pass-if "n = 1.0"
  611. (< 1.0 2.0))
  612. (pass-if "n = -1"
  613. (< -1 0))
  614. (pass-if "n = -1.0"
  615. (< -1.0 0.0))
  616. (for-each ;; FIXME: compare agains floats.
  617. (lambda (x)
  618. (pass-if (n=2^x-1 x)
  619. (< (2^x-1 x) (+ (2^x-1 x) 1)))
  620. (pass-if (n=-2^x+1 x)
  621. (< (- (2^x-1 x)) (+ (- (2^x-1 x)) 1)))
  622. (pass-if (n=2^ x)
  623. (< (2^ x) (+ (2^ x) 1)))
  624. (pass-if (n=-2^ x)
  625. (< (- (2^ x)) (+ (- (2^ x)) 1))))
  626. bit-widths))
  627. ;; Special case: n < n - 1
  628. (with-test-prefix "(< n (- n 1))"
  629. (pass-if "n = -1"
  630. (not (< -1 -2)))
  631. (pass-if "n = -1.0"
  632. (not (< -1.0 -2.0)))
  633. (for-each ;; FIXME: compare agains floats.
  634. (lambda (x)
  635. (pass-if (n=2^x-1 x)
  636. (not (< (2^x-1 x) (- (2^x-1 x) 1))))
  637. (pass-if (n=-2^x+1 x)
  638. (not (< (- (2^x-1 x)) (- (- (2^x-1 x)) 1))))
  639. (pass-if (n=2^ x)
  640. (not (< (2^ x) (- (2^ x) 1))))
  641. (pass-if (n=-2^ x)
  642. (not (< (- (2^ x)) (- (- (2^ x)) 1)))))
  643. bit-widths))
  644. ;; Special case:
  645. )