haskell: Phase 10 — Float show with .0 suffix and scientific form (+4 tests, 22/22)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m8s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m8s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -533,6 +533,58 @@
|
||||
(loop v)
|
||||
result))))
|
||||
|
||||
(define
|
||||
hk-show-num
|
||||
(fn
|
||||
(n)
|
||||
(cond
|
||||
((integer? n) (str n))
|
||||
(:else
|
||||
(let
|
||||
((a (if (< n 0) (- 0 n) n)))
|
||||
(cond
|
||||
((or (>= a 10000000) (< a 0.1)) (hk-show-float-sci n))
|
||||
(:else
|
||||
(let
|
||||
((s (str n)))
|
||||
(if (>= (index-of s ".") 0) s (str s ".0"))))))))))
|
||||
|
||||
;; ── Source-level convenience ────────────────────────────────
|
||||
(define
|
||||
hk-show-float-sci
|
||||
(fn
|
||||
(n)
|
||||
(let
|
||||
((sign (if (< n 0) "-" "")) (a (if (< n 0) (- 0 n) n)))
|
||||
(let
|
||||
((e 0) (m a))
|
||||
(begin
|
||||
(define
|
||||
hk-norm-up
|
||||
(fn
|
||||
()
|
||||
(when
|
||||
(>= m 10)
|
||||
(begin (set! m (/ m 10)) (set! e (+ e 1)) (hk-norm-up)))))
|
||||
(define
|
||||
hk-norm-down
|
||||
(fn
|
||||
()
|
||||
(when
|
||||
(< m 1)
|
||||
(begin (set! m (* m 10)) (set! e (- e 1)) (hk-norm-down)))))
|
||||
(hk-norm-up)
|
||||
(hk-norm-down)
|
||||
(let
|
||||
((mstr (str m)))
|
||||
(str
|
||||
sign
|
||||
(if (>= (index-of mstr ".") 0) mstr (str mstr ".0"))
|
||||
"e"
|
||||
e)))))))
|
||||
|
||||
;; Eagerly build the Prelude env once at load time; each call to
|
||||
;; hk-eval-expr-source copies it instead of re-parsing the whole Prelude.
|
||||
(define
|
||||
hk-show-prec
|
||||
(fn
|
||||
@@ -541,7 +593,9 @@
|
||||
((fv (hk-force v)))
|
||||
(cond
|
||||
((= (type-of fv) "number")
|
||||
(if (and (< fv 0) (>= p 11)) (str "(" fv ")") (str fv)))
|
||||
(let
|
||||
((s (hk-show-num fv)))
|
||||
(if (and (< fv 0) (>= p 11)) (str "(" s ")") s)))
|
||||
((= (type-of fv) "string") (str "\"" fv "\""))
|
||||
((= (type-of fv) "boolean") (if fv "True" "False"))
|
||||
((not (list? fv)) (str fv))
|
||||
@@ -570,11 +624,8 @@
|
||||
((s (str cname " " (hk-join-strs (map (fn (a) (hk-show-prec a 11)) args) " "))))
|
||||
(if (>= p 11) (str "(" s ")") s)))))))))
|
||||
|
||||
;; ── Source-level convenience ────────────────────────────────
|
||||
(define hk-show-val (fn (v) (hk-show-prec v 0)))
|
||||
|
||||
;; Eagerly build the Prelude env once at load time; each call to
|
||||
;; hk-eval-expr-source copies it instead of re-parsing the whole Prelude.
|
||||
(define
|
||||
hk-init-env
|
||||
(fn
|
||||
|
||||
Reference in New Issue
Block a user