real BigDecimal type (bigdec, M literals)
bigdec / 1.5M / 0.0M silently produced doubles. Add a jbigdec value type
{unscaled, scale} over Chez exact integers (host/chez/bigdec.ss): value =
unscaled * 10^-scale. An M-suffix literal reads to a :bigdec form that the back
end lowers to jolt-bigdec-from-string (same IR-leaf path as #inst/#uuid); bigdec
coerces a number/string. Equality is by value (1.0M = 1.00M true, 3M = 3 false),
str drops the M and pr keeps it, class is java.math.BigDecimal, decimal? is true.
Arithmetic contagion isn't modelled (out of scope). The old corpus cases passed
spuriously as doubles; they now exercise a genuine BigDecimal.
This commit is contained in:
parent
7db5fabc8d
commit
ab96650fbb
10 changed files with 288 additions and 191 deletions
|
|
@ -798,8 +798,7 @@
|
|||
|
||||
(defn clojure-version [] "1.11.0-jolt")
|
||||
|
||||
;; Jolt numbers are doubles; no BigDecimal, no ratios.
|
||||
(defn bigdec [x] (* 1.0 x))
|
||||
;; bigdec is a host fn (host/chez/bigdec.ss) — a real BigDecimal value type.
|
||||
(defn numerator [x] (throw (ex-info "numerator requires a ratio (Jolt has no ratios)" {})))
|
||||
(defn denominator [x] (throw (ex-info "denominator requires a ratio (Jolt has no ratios)" {})))
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
form-map-pairs form-set-items form-special? compile-ns
|
||||
form-regex? form-regex-source
|
||||
form-inst? form-inst-source form-uuid? form-uuid-source
|
||||
form-bigdec? form-bigdec-source
|
||||
form-ns-value? form-ns-value-name
|
||||
form-macro? form-expand-1 resolve-global
|
||||
form-sym-meta host-intern! form-syntax-quote-lower
|
||||
|
|
@ -463,6 +464,9 @@
|
|||
;; end emits a runtime inst/uuid value (host/chez/inst-time.ss).
|
||||
(form-inst? form) {:op :inst :source (form-inst-source form)}
|
||||
(form-uuid? form) {:op :uuid :source (form-uuid-source form)}
|
||||
;; bigdecimal literal (1.5M) -> a :bigdec leaf; the back end emits a runtime
|
||||
;; jbigdec built from the numeric text.
|
||||
(form-bigdec? form) {:op :bigdec :source (form-bigdec-source form)}
|
||||
;; a live namespace value spliced into a form (~*ns* in a macro) -> a
|
||||
;; :the-ns leaf the back end reconstructs by name at the call site.
|
||||
(form-ns-value? form) {:op :the-ns :name (form-ns-value-name form)}
|
||||
|
|
|
|||
|
|
@ -404,6 +404,8 @@
|
|||
;; #inst / #uuid literals -> runtime inst / uuid values.
|
||||
:inst (str "(jolt-inst-from-string " (chez-str-lit (:source node)) ")")
|
||||
:uuid (str "(jolt-uuid-from-string " (chez-str-lit (:source node)) ")")
|
||||
;; bigdecimal literal (1.5M) -> a runtime jbigdec from its numeric text.
|
||||
:bigdec (str "(jolt-bigdec-from-string " (chez-str-lit (:source node)) ")")
|
||||
;; a namespace value spliced into a form (~*ns*) -> reconstruct by name.
|
||||
:the-ns (str "(intern-ns! " (chez-str-lit (:name node)) ")")
|
||||
;; (.method target arg*) -> jolt-host-call for an rt-shimmed method, else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue