cs: faster number->string on flonums

This commit is contained in:
Matthew Flatt 2020-05-20 06:17:53 -06:00
parent 43c8876643
commit 07d3f3a2ec
2 changed files with 9 additions and 0 deletions

View File

@ -179,6 +179,8 @@
(test "+nan.0" number->string +nan.0)
(test "+nan.0" number->string +nan.0)
(test "1589935744527.254" number->string 1589935744527.254)
#reader "maybe-single.rkt"
(begin
(test (if has-single-flonum? "+inf.f" "+inf.0") number->string +inf.f)

View File

@ -393,6 +393,13 @@
result)]
[else
(cond
[(and (eq? radix 10)
(number? n))
;; `number->string` goes through `format` to get to an implementation
;; like this, so take a shortcut:
(let ([op (#%open-output-string)])
(#%display n op)
(#%get-output-string op))]
[(eq? radix 16)
;; Host generates uppercase letters, Racket generates lowercase
(string-downcase (#2%number->string n radix))]