diff options
author | Eduardo Julian | 2018-05-06 23:27:12 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-05-06 23:27:12 -0400 |
commit | fb72b937aba7886ce204379e97aa06c327a4029f (patch) | |
tree | 20bc243f1605c5b6c37b833b8046b82eac805494 /new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux | |
parent | 0b53bcc87ad3563daedaa64306d0bbe6df01ca49 (diff) |
- Implemented Nat functionality in pure Lux.
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux index 88b40bcca..70a9f62df 100644 --- a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux @@ -664,83 +664,6 @@ @@bit//logical-right-shift )) -(runtime: (nat//< param subject) - (with-vars [pH sH] - ($_ r.then - (r.set! pH (..int64-high (@@ param))) - (r.set! sH (..int64-high (@@ subject))) - (let [lesser-high? (|> (@@ sH) (r.< (@@ pH))) - equal-high? (|> (@@ sH) (r.= (@@ pH))) - lesser-low? (|> (..int64-low (@@ subject)) (r.< (..int64-low (@@ param))))] - (|> lesser-high? - (r.or (|> equal-high? - (r.and lesser-low?)))))))) - -(runtime: (nat/// parameter subject) - (let [negative? (int//< int//zero) - valid-division-check [(|> (@@ parameter) (int//= int//zero)) - (r.stop (r.string "Cannot divide by zero!"))] - short-circuit-check [(|> (@@ subject) (nat//< (@@ parameter))) - int//zero]] - (r.cond (list valid-division-check - short-circuit-check - - [(|> (@@ parameter) - (nat//< (|> (@@ subject) (bit//logical-right-shift (r.int 1))))) - int//one]) - (with-vars [result remainder approximate log2 approximate-result approximate-remainder delta] - ($_ r.then - (r.set! result int//zero) - (r.set! remainder (@@ subject)) - (r.while (|> (|> (@@ remainder) (nat//< (@@ parameter))) - (r.or (|> (@@ remainder) (int//= (@@ parameter))))) - (let [rough-estimate (r.apply (list (|> (int//to-float (@@ parameter)) (r./ (int//to-float (@@ remainder))))) - (r.global "floor")) - calculate-approximate-result (int//from-float (@@ approximate)) - calculate-approximate-remainder (int//* (@@ parameter) (@@ approximate-result)) - delta (r.if (|> (r.float 48.0) (r.<= (@@ log2))) - (r.float 1.0) - (r.** (|> (r.float 48.0) (r.- (@@ log2))) - (r.float 2.0))) - update-approximates! ($_ r.then - (r.set! approximate-result calculate-approximate-result) - (r.set! approximate-remainder calculate-approximate-remainder))] - ($_ r.then - (r.set! approximate (r.apply (list (r.float 1.0) rough-estimate) - (r.global "max"))) - (r.set! log2 (let [log (function (_ input) - (r.apply (list input) (r.global "log")))] - (r.apply (list (|> (log (r.int 2)) - (r./ (log (@@ approximate))))) - (r.global "ceil")))) - update-approximates! - (r.while (|> (negative? (@@ approximate-remainder)) - (r.or (|> (@@ approximate-remainder) (int//< (@@ remainder))))) - ($_ r.then - (r.set! approximate (|> delta (r.- (@@ approximate)))) - update-approximates!)) - ($_ r.then - (r.set! result (|> (@@ result) - (int//+ (r.if (|> (@@ approximate-result) (int//= int//zero)) - int//one - (@@ approximate-result))))) - (r.set! remainder (|> (@@ remainder) (int//- (@@ approximate-remainder)))))))) - (@@ result))) - ))) - -(runtime: (nat//% param subject) - (let [flat (|> (@@ subject) - (nat/// (@@ param)) - (int//* (@@ param)))] - (|> (@@ subject) (int//- flat)))) - -(def: runtime//nat - Runtime - ($_ r.then - @@nat//< - @@nat/// - @@nat//%)) - (runtime: (deg//* param subject) (with-vars [sL sH pL pH bottom middle top] ($_ r.then @@ -1035,7 +958,6 @@ runtime//bit runtime//int runtime//adt - runtime//nat runtime//deg runtime//frac runtime//text |