@end defvr
@defvr variable flonum-unparser-cutoff
-This variable controls the action of @code{number->string} when
+This fluid controls the action of @code{number->string} when
@var{number} is a flonum (and consequently controls all printing of
-flonums). The value of this variable is normally a list of three items:
+flonums). The value of this fluid is normally a list of three items:
@table @var
@item rounding-type
@example
(number->string (* 4 (atan 1 1)))
@result{} "3.141592653589793"
-(fluid-let ((flonum-unparser-cutoff '(relative 5)))
- (number->string (* 4 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(relative 5)
+ (lambda ()
+ (number->string (* 4 (atan 1 1)))))
@result{} "3.1416"
-(fluid-let ((flonum-unparser-cutoff '(relative 5)))
- (number->string (* 4000 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(relative 5)
+ (lambda ()
+ (number->string (* 4000 (atan 1 1)))))
@result{} "3141.6"
-(fluid-let ((flonum-unparser-cutoff '(relative 5 scientific)))
- (number->string (* 4000 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(relative 5 scientific)
+ (lambda ()
+ (number->string (* 4000 (atan 1 1)))))
@result{} "3.1416e3"
-(fluid-let ((flonum-unparser-cutoff '(relative 5 scientific)))
- (number->string (* 40000 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(relative 5 scientific)
+ (lambda ()
+ (number->string (* 40000 (atan 1 1)))))
@result{} "3.1416e4"
-(fluid-let ((flonum-unparser-cutoff '(relative 5 engineering)))
- (number->string (* 40000 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(relative 5 engineering)
+ (lambda ()
+ (number->string (* 40000 (atan 1 1)))))
@result{} "31.416e3"
-(fluid-let ((flonum-unparser-cutoff '(absolute 5)))
- (number->string (* 4 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(absolute 5)
+ (lambda ()
+ (number->string (* 4 (atan 1 1)))))
@result{} "3.14159"
-(fluid-let ((flonum-unparser-cutoff '(absolute 5)))
- (number->string (* 4000 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(absolute 5)
+ (lambda ()
+ (number->string (* 4000 (atan 1 1)))))
@result{} "3141.59265"
-(fluid-let ((flonum-unparser-cutoff '(absolute -4)))
- (number->string (* 4e10 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(absolute -4)
+ (lambda ()
+ (number->string (* 4e10 (atan 1 1)))))
@result{} "31415930000."
-(fluid-let ((flonum-unparser-cutoff '(absolute -4 scientific)))
- (number->string (* 4e10 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(absolute -4 scientific)
+ (lambda ()
+ (number->string (* 4e10 (atan 1 1)))))
@result{} "3.141593e10"
-(fluid-let ((flonum-unparser-cutoff '(absolute -4 engineering)))
- (number->string (* 4e10 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(absolute -4 engineering)
+ (lambda ()
+ (number->string (* 4e10 (atan 1 1)))))
@result{} "31.41593e9"
-(fluid-let ((flonum-unparser-cutoff '(absolute -5)))
- (number->string (* 4e10 (atan 1 1))))
+(let-fluid flonum-unparser-cutoff '(absolute -5)
+ (lambda ()
+ (number->string (* 4e10 (atan 1 1)))))
@result{} "31415900000."
@end example
(if (< n (expt 10 (- k 1)))
(string-append (string-pad-left (number->string n) (- k 1)) " ")
(let ((s
- (fluid-let ((flonum-unparser-cutoff `(RELATIVE ,k ENGINEERING)))
- (number->string (exact->inexact n)))))
+ (let-fluid flonum-unparser-cutoff `(RELATIVE ,k ENGINEERING)
+ (lambda ()
+ (number->string (exact->inexact n))))))
(let ((regs (re-string-match "\\([0-9.]+\\)e\\([0-9]+\\)" s)))
(let ((mantissa (re-match-extract s regs 1))
(exponent (string->number (re-match-extract s regs 2))))
exponent)))))
\f
(define (flonum-unparser-cutoff-args)
- (cond ((eq? 'NORMAL flonum-unparser-cutoff)
- (values 'NORMAL 0 flonum-unparser:normal-output))
- ((and (pair? flonum-unparser-cutoff)
- (pair? (cdr flonum-unparser-cutoff))
- (let ((mode (car flonum-unparser-cutoff))
- (place (cadr flonum-unparser-cutoff)))
- (and (memq mode '(ABSOLUTE RELATIVE NORMAL))
- (exact-integer? place)
- (or (not (eq? 'RELATIVE mode))
- (positive? place))))
- (or (null? (cddr flonum-unparser-cutoff))
- (and (pair? (cddr flonum-unparser-cutoff))
- (null? (cdddr flonum-unparser-cutoff))
- (let ((mode (caddr flonum-unparser-cutoff)))
- (or (memq mode '(NORMAL SCIENTIFIC ENGINEERING))
- (and (procedure? mode)
- (procedure-arity-valid? mode 3)))))))
- (values (car flonum-unparser-cutoff)
- (- (cadr flonum-unparser-cutoff))
- (if (null? (cddr flonum-unparser-cutoff))
- flonum-unparser:normal-output
- (lookup-symbolic-display-mode
- (caddr flonum-unparser-cutoff)))))
- (else
- (warn "illegal flonum unparser cutoff parameter"
- flonum-unparser-cutoff)
- (values 'NORMAL 0 flonum-unparser:normal-output))))
+ (let ((cutoff (fluid flonum-unparser-cutoff)))
+ (cond ((eq? 'NORMAL cutoff)
+ (values 'NORMAL 0 flonum-unparser:normal-output))
+ ((and (pair? cutoff)
+ (pair? (cdr cutoff))
+ (let ((mode (car cutoff))
+ (place (cadr cutoff)))
+ (and (memq mode '(ABSOLUTE RELATIVE NORMAL))
+ (exact-integer? place)
+ (or (not (eq? 'RELATIVE mode))
+ (positive? place))))
+ (or (null? (cddr cutoff))
+ (and (pair? (cddr cutoff))
+ (null? (cdddr cutoff))
+ (let ((mode (caddr cutoff)))
+ (or (memq mode '(NORMAL SCIENTIFIC ENGINEERING))
+ (and (procedure? mode)
+ (procedure-arity-valid? mode 3)))))))
+ (values (car cutoff)
+ (- (cadr cutoff))
+ (if (null? (cddr cutoff))
+ flonum-unparser:normal-output
+ (lookup-symbolic-display-mode
+ (caddr cutoff)))))
+ (else
+ (warn "illegal flonum unparser cutoff parameter"
+ cutoff)
+ (values 'NORMAL 0 flonum-unparser:normal-output)))))
(define (lookup-symbolic-display-mode mode)
(case mode
(else mode)))
(define flonum-unparser-hook #f)
-(define flonum-unparser-cutoff 'NORMAL)
+(define flonum-unparser-cutoff)
(define (dragon4-normalize x precision)
(call-with-values (lambda () (flo:normalize x))
(define expt-radix)
(define (initialize-dragon4!)
+ (set! flonum-unparser-cutoff (make-fluid 'NORMAL))
(set! expt-radix
(let ((v (make-initialized-vector 310 (lambda (i) (expt 10 i)))))
(lambda (base exponent)
(define (test)
(define (try n settings . expecteds)
- (let ((got (fluid-let ((flonum-unparser-cutoff settings))
- (number->string (exact->inexact n)))))
+ (let ((got (let-fluid flonum-unparser-cutoff settings
+ (lambda ()
+ (number->string (exact->inexact n))))))
(if (member got expecteds)
(set! successes (+ successes 1))
(begin
(let ((f1-time (run-test f1-test)))
(let ((report
(lambda (name time scale)
- (fluid-let ((flonum-unparser-cutoff '(ABSOLUTE 2)))
- (newline)
- (write name)
- (write-string "-test:\t")
- (write (exact->inexact time))
- (write-string "\t")
- (write (exact->inexact (/ (/ time scale) f1-time)))))))
+ (let-fluid flonum-unparser-cutoff '(ABSOLUTE 2)
+ (lambda ()
+ (newline)
+ (write name)
+ (write-string "-test:\t")
+ (write (exact->inexact time))
+ (write-string "\t")
+ (write (exact->inexact (/ (/ time scale) f1-time))))))))
(report 'f1 f1-time 1)
(for-each (lambda (name test scale)
(report name (run-test test) scale))