|
589 | 589 | (format nil "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F"
|
590 | 590 | x x x x x x))
|
591 | 591 |
|
| 592 | +;; big-pos-ratio is a ratio value that is larger than |
| 593 | +;; Double/MAX_VALUE, and has a non-terminating decimal representation |
| 594 | +;; if you attempt to represent it exactly. |
| 595 | +(def big-pos-ratio (/ (* 4 (bigint (. BigDecimal valueOf Double/MAX_VALUE))) 3)) |
| 596 | +(def big-neg-ratio (- big-pos-ratio)) |
| 597 | +;; tiny-pos-ratio is a ratio between 0 and Double/MIN_VALUE. |
| 598 | +(def tiny-pos-ratio (/ 1 (bigint (apply str (cons "1" (repeat 340 "0")))))) |
| 599 | +(def tiny-neg-ratio (- tiny-pos-ratio)) |
| 600 | + |
592 | 601 | (simple-tests cltl-F-tests
|
| 602 | + (cl-format false "~10,3f" 4/5) " 0.800" |
| 603 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 604 | + (cl-format false "~10,3f" big-pos-ratio)) "239692417981642093333333333333333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000" |
| 605 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 606 | + (cl-format false "~10,3f" big-neg-ratio)) "-239692417981642093333333333333333300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000" |
| 607 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 608 | + (cl-format false "~10,3f" tiny-pos-ratio)) " 0.000" |
| 609 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 610 | + (cl-format false "~10,3f" tiny-neg-ratio)) " -0.000" |
593 | 611 | (foo 3.14159) " 3.14| 31.42| 3.14|3.1416|3.14|3.14159"
|
| 612 | + (foo 314159/100000) |
| 613 | + " 3.14| 31.42| 3.14|3.1416|3.14|3.14159" |
594 | 614 | (foo -3.14159) " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159"
|
595 | 615 | (foo 100.0) "100.00|******|100.00| 100.0|100.00|100.0"
|
596 | 616 | (foo 1234.0) "1234.00|******|??????|1234.0|1234.00|1234.0"
|
|
603 | 623 |
|
604 | 624 | ;; Clojure doesn't support float/double differences in representation
|
605 | 625 | (simple-tests cltl-E-tests
|
| 626 | + (cl-format false "~10,3e" 4/5) " 8.000E-1" |
| 627 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 628 | + (cl-format false "~10,3e" big-pos-ratio)) "2.397E+308" |
| 629 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 630 | + (cl-format false "~10,3e" big-neg-ratio)) "-2.397E+308" |
| 631 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 632 | + (cl-format false "~10,3e" tiny-pos-ratio)) "1.000E-340" |
| 633 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 634 | + (cl-format false "~10,3e" tiny-neg-ratio)) "-1.000E-340" |
606 | 635 | (foo-e 0.0314159) " 3.14E-2| 31.42$-03|+.003E+01| 3.14E-2" ; Added this one
|
| 636 | + (foo-e 314159/10000000) |
| 637 | + " 3.14E-2| 31.42$-03|+.003E+01| 3.14E-2" |
607 | 638 | (foo-e 3.14159) " 3.14E+0| 31.42$-01|+.003E+03| 3.14E+0"
|
608 | 639 | (foo-e -3.14159) " -3.14E+0|-31.42$-01|-.003E+03| -3.14E+0"
|
609 | 640 | (foo-e 1100.0) " 1.10E+3| 11.00$+02|+.001E+06| 1.10E+3"
|
|
641 | 672 |
|
642 | 673 | ;; Clojure doesn't support float/double differences in representation
|
643 | 674 | (simple-tests cltl-G-tests
|
| 675 | + (cl-format false "~10,3g" 4/5) " 0.800 " |
| 676 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 677 | + (cl-format false "~10,3g" big-pos-ratio)) "2.397E+308" |
| 678 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 679 | + (cl-format false "~10,3g" big-neg-ratio)) "-2.397E+308" |
| 680 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 681 | + (cl-format false "~10,3g" tiny-pos-ratio)) "1.000E-340" |
| 682 | + (binding [*math-context* java.math.MathContext/DECIMAL128] |
| 683 | + (cl-format false "~10,3g" tiny-neg-ratio)) "-1.000E-340" |
644 | 684 | (foo-g 0.0314159) " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2"
|
| 685 | + (foo-g 314159/10000000) |
| 686 | + " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2" |
645 | 687 | (foo-g 0.314159) " 0.31 |0.314 |0.314 | 0.31 "
|
646 | 688 | (foo-g 3.14159) " 3.1 | 3.14 | 3.14 | 3.1 "
|
647 | 689 | (foo-g 31.4159) " 31. | 31.4 | 31.4 | 31. "
|
|
0 commit comments