mirror of https://github.com/logseq/logseq
use bignumber.js for calculations
parent
421d800676
commit
dcddb9e935
|
@ -82,6 +82,7 @@
|
|||
"@sentry/tracing": "^6.18.2",
|
||||
"@tabler/icons": "1.54.0",
|
||||
"@tippyjs/react": "4.2.5",
|
||||
"bignumber.js": "^9.0.2",
|
||||
"capacitor-voice-recorder": "2.1.0",
|
||||
"chokidar": "3.5.1",
|
||||
"chrono-node": "2.2.4",
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
(:require [clojure.edn :as edn]
|
||||
[clojure.string :as str]
|
||||
[frontend.util :as util]
|
||||
|
||||
[bignumber.js :as bn]
|
||||
|
||||
#?(:clj [clojure.java.io :as io])
|
||||
#?(:cljs [shadow.resource :as rc])
|
||||
#?(:cljs [rum.core :as rum])
|
||||
|
@ -24,17 +27,19 @@
|
|||
|
||||
(defn new-env [] (atom {}))
|
||||
|
||||
;; TODO: Set DECIMAL_PLACES https://mikemcl.github.io/bignumber.js/#decimal-places
|
||||
|
||||
(defn eval* [env ast]
|
||||
(insta/transform
|
||||
{:number (comp edn/read-string #(str/replace % "," ""))
|
||||
{:number (comp bn/BigNumber #(str/replace % "," ""))
|
||||
:percent (fn percent [a] (/ a 100.00))
|
||||
:scientific edn/read-string
|
||||
:negterm (fn neg [a] (- a))
|
||||
:expr identity
|
||||
:add +
|
||||
:sub -
|
||||
:mul *
|
||||
:div /
|
||||
:add (fn add [a b] (-> a (.plus b)))
|
||||
:sub (fn sub [a b] (-> a (.minus b)))
|
||||
:mul (fn mul [a b] (-> a (.multipliedBy b)))
|
||||
:div (fn div [a b] (-> a (.dividedBy b)))
|
||||
:pow (fn pow [a b]
|
||||
#?(:clj (java.lang.Math/pow a b) :cljs (js/Math.pow a b)))
|
||||
:log (fn log [a]
|
||||
|
@ -101,4 +106,4 @@
|
|||
[:span (cond
|
||||
(nil? line) ""
|
||||
(failure? line) "?"
|
||||
:else line)]])])))
|
||||
:else (str line))]])])))
|
||||
|
|
|
@ -1651,6 +1651,11 @@ big-integer@1.6.x:
|
|||
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.51.tgz#0df92a5d9880560d3ff2d5fd20245c889d130686"
|
||||
integrity sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==
|
||||
|
||||
bignumber.js@^9.0.2:
|
||||
version "9.0.2"
|
||||
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.2.tgz#71c6c6bed38de64e24a65ebe16cfcf23ae693673"
|
||||
integrity sha512-GAcQvbpsM0pUb0zw1EI0KhQEZ+lRwR5fYaAp3vPOYuP7aDvGy6cVN6XHLauvF8SOga2y0dcLcjt3iQDTSEliyw==
|
||||
|
||||
binary-extensions@^1.0.0:
|
||||
version "1.13.1"
|
||||
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
|
||||
|
|
Loading…
Reference in New Issue