remove bigfloat support to avoid bug in v.5.3.x

pull/1/head
Matthew Butterick 10 years ago
parent 21308f2855
commit 589305ee09

@ -1,202 +1,199 @@
#lang racket
;;; describe-test.rkt
;;; Copyright (c) 2009-2010 M. Douglas Williams
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;
(require math/bigfloat
racket/mpair)
(require (planet williams/describe/describe))
;;; Booleans
(printf "~n--- Booleans ---~n")
(describe #t)
(describe #f)
;;; Numbers
(printf "~n--- Numbers ---~n")
(define (! n)
(if (= n 0)
1
(* n (! (sub1 n)))))
(describe +inf.0)
(describe -inf.0)
(describe +nan.0)
(describe 0)
(describe (! 10))
(describe (! 40))
(describe (- (! 40) (! 41)))
(describe (! 100))
(describe (/ (! 10) (add1 (! 11))))
(describe -1+3i)
(describe 0.0)
(describe 0.1e0)
(describe 0.1f0)
(describe 0.1t0)
(describe (* (! 10) 1.0))
(describe 6.0221313e23)
(describe 6.0221313f23)
(describe 6.0221313t23)
(describe (exact->inexact (! 40)))
(describe (sqrt 10))
(describe (sqrt -10))
(describe (+ (sqrt 10) (sqrt -10)))
(describe (bf 1/10))
(describe (bf "15e200000000"))
;;; Strings
(printf "~n--- Strings ---~n")
(describe "abc")
(describe (string #\1 #\2 #\3))
;;; Byte Strings
(printf "~n--- Byte Strings ---~n")
(describe #"abc")
(describe (bytes 48 49 50))
;;; Characters
(printf "~n--- Characters ---~n")
(describe #\a)
(describe #\A)
(describe #\0)
(describe #\()
;;; Symbols
(printf "~n--- Symbols ---~n")
(describe 'abc)
(describe '|(a + b)|)
(describe (gensym))
;;; Regular Expressions
(printf "~n--- Regular Expressions ---~n")
(describe #rx"Ap*le")
(describe #px"Ap*le")
;;; Byte Regular Expressions
(printf "~n--- Byte Regular Expressions ---~n")
(describe #rx#"Ap*le")
(describe #px#"Ap*le")
;;; Keywords
(printf "~n--- Keywords ---~n")
(describe '#:key)
;;; Lists and Pairs
(printf "~n--- Lists and Pairs ---~n")
(describe '(this is a proper list))
(describe '(this is an improper . list))
(describe (list '(this . is) '(also . a) '(proper . list)))
;;; Mutable Lists and Pairs
(printf "~n--- Mutable Lists and Pairs ---~n")
(describe (mlist 'this 'is 'a 'proper 'list))
(describe (mcons 'this (mcons 'is (mcons 'an (mcons 'improper 'list)))))
(describe (mlist '(this . is) '(also . a) '(proper . list)))
;;; Vectors
(printf "~n--- Vectors ---~n")
(describe #(1 2 3))
;;; Boxes
(printf "~n--- Boxes ---~n")
(describe (box 12))
(describe (box (box 'a)))
(describe (box (sqrt 10)))
;;; Weak Boxes
(printf "~n--- Weak Boxes ---~n")
(describe (make-weak-box 12))
(describe (make-weak-box (make-weak-box 'a)))
(describe (make-weak-box (sqrt 10)))
;;; Hashes
(printf "~n--- Hashes ---~n")
(describe #hash((a . 12) (b . 14) (c . 16)))
(describe #hasheq((a . a) (b . b) (c . c)))
(describe #hasheqv((a . #\a) (b . #\b) (c . #\c)))
(define ht (make-hash))
(hash-set! ht 'a 12)
(hash-set! ht 'b 14)
(hash-set! ht 'c 16)
(describe ht)
(define wht (make-weak-hash))
(hash-set! wht 'a 12)
(hash-set! wht 'b 14)
(hash-set! wht 'c 16)
(describe wht)
;;; Procedures
(printf "~n--- Procedures ---~n")
(describe car)
(describe open-output-file)
(describe current-input-port)
(describe (lambda (x) x))
;;; Ports
(printf "~n--- Ports ---~n")
(describe (current-input-port))
(describe (current-output-port))
;;; Void
(printf "~n--- Void ---~n")
(describe (void))
;;; EOF
(printf "~n--- EOF ---~n")
(describe eof)
;;; Paths
(printf "~n--- Paths ---~n")
(describe (string->path "C:\\Program-files\\PLT"))
(describe (string->path "../dir/file.ext"))
;;; Structures
(printf "~n--- Structures ---~n")
(define-struct transparent-struct (a b c) #:transparent)
(define ts-1 (make-transparent-struct 'a 'b 'c))
(describe ts-1)
;;; Other Named Things (I.E., Opaque Structures)
(printf "~n--- Other Named Things ---~n")
(define-struct opaque-struct (a b c))
(define os-1 (make-opaque-struct 'a 'b 'c))
(describe os-1)
#lang racket
;;; describe-test.rkt
;;; Copyright (c) 2009-2010 M. Douglas Williams
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;
(require racket/mpair)
(require (planet williams/describe/describe))
;;; Booleans
(printf "~n--- Booleans ---~n")
(describe #t)
(describe #f)
;;; Numbers
(printf "~n--- Numbers ---~n")
(define (! n)
(if (= n 0)
1
(* n (! (sub1 n)))))
(describe +inf.0)
(describe -inf.0)
(describe +nan.0)
(describe 0)
(describe (! 10))
(describe (! 40))
(describe (- (! 40) (! 41)))
(describe (! 100))
(describe (/ (! 10) (add1 (! 11))))
(describe -1+3i)
(describe 0.0)
(describe 0.1e0)
(describe 0.1f0)
(describe 0.1t0)
(describe (* (! 10) 1.0))
(describe 6.0221313e23)
(describe 6.0221313f23)
(describe 6.0221313t23)
(describe (exact->inexact (! 40)))
(describe (sqrt 10))
(describe (sqrt -10))
(describe (+ (sqrt 10) (sqrt -10)))
;;; Strings
(printf "~n--- Strings ---~n")
(describe "abc")
(describe (string #\1 #\2 #\3))
;;; Byte Strings
(printf "~n--- Byte Strings ---~n")
(describe #"abc")
(describe (bytes 48 49 50))
;;; Characters
(printf "~n--- Characters ---~n")
(describe #\a)
(describe #\A)
(describe #\0)
(describe #\()
;;; Symbols
(printf "~n--- Symbols ---~n")
(describe 'abc)
(describe '|(a + b)|)
(describe (gensym))
;;; Regular Expressions
(printf "~n--- Regular Expressions ---~n")
(describe #rx"Ap*le")
(describe #px"Ap*le")
;;; Byte Regular Expressions
(printf "~n--- Byte Regular Expressions ---~n")
(describe #rx#"Ap*le")
(describe #px#"Ap*le")
;;; Keywords
(printf "~n--- Keywords ---~n")
(describe '#:key)
;;; Lists and Pairs
(printf "~n--- Lists and Pairs ---~n")
(describe '(this is a proper list))
(describe '(this is an improper . list))
(describe (list '(this . is) '(also . a) '(proper . list)))
;;; Mutable Lists and Pairs
(printf "~n--- Mutable Lists and Pairs ---~n")
(describe (mlist 'this 'is 'a 'proper 'list))
(describe (mcons 'this (mcons 'is (mcons 'an (mcons 'improper 'list)))))
(describe (mlist '(this . is) '(also . a) '(proper . list)))
;;; Vectors
(printf "~n--- Vectors ---~n")
(describe #(1 2 3))
;;; Boxes
(printf "~n--- Boxes ---~n")
(describe (box 12))
(describe (box (box 'a)))
(describe (box (sqrt 10)))
;;; Weak Boxes
(printf "~n--- Weak Boxes ---~n")
(describe (make-weak-box 12))
(describe (make-weak-box (make-weak-box 'a)))
(describe (make-weak-box (sqrt 10)))
;;; Hashes
(printf "~n--- Hashes ---~n")
(describe #hash((a . 12) (b . 14) (c . 16)))
(describe #hasheq((a . a) (b . b) (c . c)))
(describe #hasheqv((a . #\a) (b . #\b) (c . #\c)))
(define ht (make-hash))
(hash-set! ht 'a 12)
(hash-set! ht 'b 14)
(hash-set! ht 'c 16)
(describe ht)
(define wht (make-weak-hash))
(hash-set! wht 'a 12)
(hash-set! wht 'b 14)
(hash-set! wht 'c 16)
(describe wht)
;;; Procedures
(printf "~n--- Procedures ---~n")
(describe car)
(describe open-output-file)
(describe current-input-port)
(describe (lambda (x) x))
;;; Ports
(printf "~n--- Ports ---~n")
(describe (current-input-port))
(describe (current-output-port))
;;; Void
(printf "~n--- Void ---~n")
(describe (void))
;;; EOF
(printf "~n--- EOF ---~n")
(describe eof)
;;; Paths
(printf "~n--- Paths ---~n")
(describe (string->path "C:\\Program-files\\PLT"))
(describe (string->path "../dir/file.ext"))
;;; Structures
(printf "~n--- Structures ---~n")
(define-struct transparent-struct (a b c) #:transparent)
(define ts-1 (make-transparent-struct 'a 'b 'c))
(describe ts-1)
;;; Other Named Things (I.E., Opaque Structures)
(printf "~n--- Other Named Things ---~n")
(define-struct opaque-struct (a b c))
(define os-1 (make-opaque-struct 'a 'b 'c))
(describe os-1)

@ -1,39 +0,0 @@
#lang racket
(require math/bigfloat)
(require (planet williams/describe/describe))
(printf "--- Using literals (big float) ---~n")
(describe (bf 1/10))
(describe (bf 2/10))
(describe (bf 3/10))
(describe (bf 4/10))
(describe (bf 5/10))
(describe (bf 6/10))
(describe (bf 7/10))
(describe (bf 8/10))
(describe (bf 9/10))
(describe (bf 10/10))
(printf "--- Exact decimal values of big floats ---~n")
(float->string (bf 1/10))
(float->string (bf 2/10))
(float->string (bf 3/10))
(float->string (bf 4/10))
(float->string (bf 5/10))
(float->string (bf 6/10))
(float->string (bf 7/10))
(float->string (bf 8/10))
(float->string (bf 9/10))
(float->string (bf 10/10))
(printf "--- Using summation (big float) ---~n")
(for/fold ((sum 0.bf))
((i (in-range 10)))
(define new-sum (bf+ sum (bf 1/10)))
(describe new-sum)
new-sum)
(printf "--- Using product (big float) ---~n")
(for ((i (in-range 1 11)))
(describe (bf* (bf i) (bf 1/10))))

@ -70,8 +70,7 @@
;;; 2.0.1 08/26/13 Added exact decimal value for floats. (MDW)
;;; 2.0.1 09/26/13 Added bigfloat support to float->string. (MDW)
(require math/bigfloat
racket/extflonum
(require racket/extflonum
racket/mpair)
;;; (variant x) -> symbol
@ -339,11 +338,7 @@
; ((extfl> x 0.0t0) +1.0)
; (else 0.0))
; (sgn x)))
(define sign (cond ((bigfloat? x)
(cond ((bf< x 0.bf) -1.0)
((bf> x 0.bf) +1.0)
(else 0.0)))
((extflonum? x)
(define sign (cond ((extflonum? x)
(cond ((extfl< x 0.0t0) -1.0)
((extfl> x 0.0t0) +1.0)
(else 0.0)))
@ -353,8 +348,7 @@
;(define exact-x (if (extflonum? x)
; (abs (extfl->exact x))
; (abs (inexact->exact x))))
(define exact-x (cond ((bigfloat? x) (abs (bigfloat->rational x)))
((extflonum? x) (abs (extfl->exact x)))
(define exact-x (cond ((extflonum? x) (abs (extfl->exact x)))
(else (inexact->exact x))))
(define int (truncate exact-x))
(define frac (- exact-x int))
@ -421,20 +415,6 @@
(format "~s is an extended precision (80-bit) floating point number whose exact decimal value is ~a"
x (float->string x)))))
;;; (bigfloat-description x) -> string
;;; x : extflonum?
;;; Returns a string describing the big float, x.
(define (bigfloat-description x)
(cond ((eqv? x +inf.bf)
(format "~s is positive infinity" x))
((eqv? x -inf.bf)
(format "~s is negative infinity" x))
((eqv? x +nan.bf)
(format "~s is non-a-number" x))
(else
(format "~s is a ~a big float with ~a bits of precision"
x (if (bfnegative? x) "negative" "positive")
(bigfloat-precision x)))))
;;; (string-description str) -> string?
;;; str : string?
@ -795,8 +775,6 @@
(number-description x))
((extflonum? x)
(extflonum-description x))
((bigfloat? x)
(bigfloat-description x))
((string? x)
(string-description x))
((bytes? x)
@ -863,7 +841,7 @@
(integer->string
(-> exact-integer? string?))
(float->string
(-> (or/c flonum? single-flonum? extflonum? bigfloat?) string?))
(-> (or/c flonum? single-flonum? extflonum?) string?))
(description
(-> any/c string?))
(describe

@ -8,12 +8,14 @@
@title[#:tag "describe"]{Describe}
M. Douglas Williams
@(author+email @tt{M. Douglas Williams} "doug@cognidrome.org")
@author[(author+email "M. Douglas Williams" "doug@cognidrome.org")]
This library provides functions to describe Racket objects. Currently, the following types of objects are described:
@margin-note{This is not the official version of Describe. It is the 1.5 version from PLaneT, retooled to use Racket's new package system, and with bigfloat support disabled (because of bugs related to v.5.3.x compatability.) The canonical version of Describe is on the @link["http://planet.racket-lang.org/display.ss?package=describe.plt&owner=williams" "PLaneT server"]. — MB}
@itemize{
@item{Booleans}
@item{Numbers}
@ -78,11 +80,8 @@ Examples:
@scheme[(integer->string (expt 10 150))] -> "at least 10^102"
@defproc[(float->string (x (or/c flonum? single-flonum? extflonum? bigfloat?))) string?]{
Returns a string with the exact decimal value of the floating-point number @scheme[x]. This works for single precision, double precision, extended precision, and big floating-point values. Note that internally @scheme[x] is converted to an exact rational number as part of converting to a string and the following warning from the Arbitrary-Precision Floating-Point Numbers (Bigfloats) section in the Math Library is important.
@bold{Be careful with exact conversions.} Bigfloats with large exponents may not fit in memory as integers or exact rationals. Worse, they might fit, but have all your RAM and swap space for lunch.
}
@defproc[(float->string (x (or/c flonum? single-flonum? extflonum?))) string?]{
Returns a string with the exact decimal value of the floating-point number @scheme[x]. This works for single precision, double precision, and extended precision values. Note that internally @scheme[x] is converted to an exact rational number as part of converting to a string.}
Examples:
@ -96,8 +95,6 @@ Examples:
@scheme[(float->string 0.1t0)] -> "0.1000000000000000000013552527156068805425093160010874271392822265625"
@scheme[(float->string (bf 1/10))] -> "0.10000000000000000000000000000000000000007346839692639296924804603357639035486366659729825547009429698164240107871592044830322265625"
@defproc[(describe (x any/c)) void?]{
Prints a description of @scheme[x] to the current output port.}
@ -169,9 +166,6 @@ racket
(describe (sqrt -10))
(describe (+ (sqrt 10) (sqrt -10)))
(describe (bf 1/10))
(describe (bf "15e200000000"))
;;; Strings
(printf "~n--- Strings ---~n")
@ -344,8 +338,6 @@ Produces the following output.
3.1622776601683795 is an inexact positive real number whose exact decimal value is 3.162277660168379522787063251598738133907318115234375
0+3.1622776601683795i is an inexact positive imaginary number whose exact decimal value is 0+3.162277660168379522787063251598738133907318115234375i
3.1622776601683795+3.1622776601683795i is an inexact complex number whose real part 3.1622776601683795 is an inexact positive real number whose exact decimal value is 3.162277660168379522787063251598738133907318115234375 and whose imaginary part 0+3.1622776601683795i is an inexact positive imaginary number whose exact decimal value is 0+3.162277660168379522787063251598738133907318115234375i
(bf #e0.1000000000000000000000000000000000000001) is a positive big float with 128 bits of precision
(bf "1.499999999999999999999999999999999999998e200000001") is a positive big float with 128 bits of precision
--- Strings ---
"abc" is an immutable string of length 3

Loading…
Cancel
Save