@elaraai/east 1.0.84 → 1.0.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/dist/src/analyze.d.ts.map +1 -1
  2. package/dist/src/analyze.js +48 -0
  3. package/dist/src/analyze.js.map +1 -1
  4. package/dist/src/ast_to_ir.coerce_to.spec.js +4 -4
  5. package/dist/src/ast_to_ir.coerce_to.spec.js.map +1 -1
  6. package/dist/src/ast_to_ir.d.ts +6 -1
  7. package/dist/src/ast_to_ir.d.ts.map +1 -1
  8. package/dist/src/ast_to_ir.js +20 -7
  9. package/dist/src/ast_to_ir.js.map +1 -1
  10. package/dist/src/builtins.d.ts +1 -1
  11. package/dist/src/builtins.d.ts.map +1 -1
  12. package/dist/src/builtins.js +52 -0
  13. package/dist/src/builtins.js.map +1 -1
  14. package/dist/src/codegen/canonical.d.ts +37 -0
  15. package/dist/src/codegen/canonical.d.ts.map +1 -0
  16. package/dist/src/codegen/canonical.js +208 -0
  17. package/dist/src/codegen/canonical.js.map +1 -0
  18. package/dist/src/codegen/codegen.spec.js +132 -201
  19. package/dist/src/codegen/codegen.spec.js.map +1 -1
  20. package/dist/src/codegen/printer.d.ts.map +1 -1
  21. package/dist/src/codegen/printer.js +142 -24
  22. package/dist/src/codegen/printer.js.map +1 -1
  23. package/dist/src/codegen/spellings.d.ts +4 -1
  24. package/dist/src/codegen/spellings.d.ts.map +1 -1
  25. package/dist/src/codegen/spellings.js +5 -1
  26. package/dist/src/codegen/spellings.js.map +1 -1
  27. package/dist/src/compile/builtins/index.d.ts.map +1 -1
  28. package/dist/src/compile/builtins/index.js +2 -0
  29. package/dist/src/compile/builtins/index.js.map +1 -1
  30. package/dist/src/compile/builtins/primitives.d.ts.map +1 -1
  31. package/dist/src/compile/builtins/primitives.js +2 -1
  32. package/dist/src/compile/builtins/primitives.js.map +1 -1
  33. package/dist/src/compile/builtins/query.d.ts +10 -0
  34. package/dist/src/compile/builtins/query.d.ts.map +1 -0
  35. package/dist/src/compile/builtins/query.js +5 -0
  36. package/dist/src/compile/builtins/query.js.map +1 -0
  37. package/dist/src/expr/block.d.ts.map +1 -1
  38. package/dist/src/expr/block.js +2 -1
  39. package/dist/src/expr/block.js.map +1 -1
  40. package/dist/src/expr/index.d.ts +75 -47
  41. package/dist/src/expr/index.d.ts.map +1 -1
  42. package/dist/src/expr/index.js +31 -0
  43. package/dist/src/expr/index.js.map +1 -1
  44. package/dist/src/expr/libs/datetime.d.ts +20 -20
  45. package/dist/src/expr/libs/datetime.d.ts.map +1 -1
  46. package/dist/src/expr/libs/datetime.js +208 -167
  47. package/dist/src/expr/libs/datetime.js.map +1 -1
  48. package/dist/src/expr/libs/float.d.ts +15 -15
  49. package/dist/src/expr/libs/float.d.ts.map +1 -1
  50. package/dist/src/expr/libs/float.js +298 -267
  51. package/dist/src/expr/libs/float.js.map +1 -1
  52. package/dist/src/expr/libs/integer.d.ts +12 -12
  53. package/dist/src/expr/libs/integer.d.ts.map +1 -1
  54. package/dist/src/expr/libs/integer.js +219 -194
  55. package/dist/src/expr/libs/integer.js.map +1 -1
  56. package/dist/src/expr/libs/lazy.d.ts +28 -0
  57. package/dist/src/expr/libs/lazy.d.ts.map +1 -0
  58. package/dist/src/expr/libs/lazy.js +55 -0
  59. package/dist/src/expr/libs/lazy.js.map +1 -0
  60. package/dist/src/expr/libs/lazy.spec.d.ts +6 -0
  61. package/dist/src/expr/libs/lazy.spec.d.ts.map +1 -0
  62. package/dist/src/expr/libs/lazy.spec.js +102 -0
  63. package/dist/src/expr/libs/lazy.spec.js.map +1 -0
  64. package/dist/src/expr/query.d.ts +60 -0
  65. package/dist/src/expr/query.d.ts.map +1 -0
  66. package/dist/src/expr/query.js +84 -0
  67. package/dist/src/expr/query.js.map +1 -0
  68. package/dist/src/functions.crossimport.spec.js +8 -0
  69. package/dist/src/functions.crossimport.spec.js.map +1 -1
  70. package/dist/src/functions.d.ts +45 -8
  71. package/dist/src/functions.d.ts.map +1 -1
  72. package/dist/src/functions.js +138 -28
  73. package/dist/src/functions.js.map +1 -1
  74. package/dist/src/functions.spec.js +60 -2
  75. package/dist/src/functions.spec.js.map +1 -1
  76. package/dist/src/index.d.ts +3 -0
  77. package/dist/src/index.d.ts.map +1 -1
  78. package/dist/src/index.js +3 -0
  79. package/dist/src/index.js.map +1 -1
  80. package/dist/src/internal.d.ts +4 -0
  81. package/dist/src/internal.d.ts.map +1 -1
  82. package/dist/src/internal.js +9 -0
  83. package/dist/src/internal.js.map +1 -1
  84. package/dist/src/location.d.ts +22 -0
  85. package/dist/src/location.d.ts.map +1 -1
  86. package/dist/src/location.js +31 -0
  87. package/dist/src/location.js.map +1 -1
  88. package/dist/src/naming.d.ts +5 -3
  89. package/dist/src/naming.d.ts.map +1 -1
  90. package/dist/src/naming.js.map +1 -1
  91. package/dist/src/portable.spec.d.ts +6 -0
  92. package/dist/src/portable.spec.d.ts.map +1 -0
  93. package/dist/src/portable.spec.js +181 -0
  94. package/dist/src/portable.spec.js.map +1 -0
  95. package/dist/src/query/evaluate.d.ts +98 -0
  96. package/dist/src/query/evaluate.d.ts.map +1 -0
  97. package/dist/src/query/evaluate.js +193 -0
  98. package/dist/src/query/evaluate.js.map +1 -0
  99. package/dist/src/query/index.d.ts +17 -0
  100. package/dist/src/query/index.d.ts.map +1 -0
  101. package/dist/src/query/index.js +17 -0
  102. package/dist/src/query/index.js.map +1 -0
  103. package/dist/src/query/jq/catalog.d.ts +174 -0
  104. package/dist/src/query/jq/catalog.d.ts.map +1 -0
  105. package/dist/src/query/jq/catalog.js +1740 -0
  106. package/dist/src/query/jq/catalog.js.map +1 -0
  107. package/dist/src/query/jq/check.d.ts +210 -0
  108. package/dist/src/query/jq/check.d.ts.map +1 -0
  109. package/dist/src/query/jq/check.js +2261 -0
  110. package/dist/src/query/jq/check.js.map +1 -0
  111. package/dist/src/query/jq/complete.d.ts +89 -0
  112. package/dist/src/query/jq/complete.d.ts.map +1 -0
  113. package/dist/src/query/jq/complete.js +320 -0
  114. package/dist/src/query/jq/complete.js.map +1 -0
  115. package/dist/src/query/jq/describe.d.ts +53 -0
  116. package/dist/src/query/jq/describe.d.ts.map +1 -0
  117. package/dist/src/query/jq/describe.js +149 -0
  118. package/dist/src/query/jq/describe.js.map +1 -0
  119. package/dist/src/query/jq/lex.d.ts +118 -0
  120. package/dist/src/query/jq/lex.d.ts.map +1 -0
  121. package/dist/src/query/jq/lex.js +371 -0
  122. package/dist/src/query/jq/lex.js.map +1 -0
  123. package/dist/src/query/jq/literals.d.ts +49 -0
  124. package/dist/src/query/jq/literals.d.ts.map +1 -0
  125. package/dist/src/query/jq/literals.js +78 -0
  126. package/dist/src/query/jq/literals.js.map +1 -0
  127. package/dist/src/query/jq/messages.d.ts +126 -0
  128. package/dist/src/query/jq/messages.d.ts.map +1 -0
  129. package/dist/src/query/jq/messages.js +172 -0
  130. package/dist/src/query/jq/messages.js.map +1 -0
  131. package/dist/src/query/jq/parse.d.ts +70 -0
  132. package/dist/src/query/jq/parse.d.ts.map +1 -0
  133. package/dist/src/query/jq/parse.js +1013 -0
  134. package/dist/src/query/jq/parse.js.map +1 -0
  135. package/dist/src/query/jq/print.d.ts +59 -0
  136. package/dist/src/query/jq/print.d.ts.map +1 -0
  137. package/dist/src/query/jq/print.js +587 -0
  138. package/dist/src/query/jq/print.js.map +1 -0
  139. package/dist/src/query/jq/shapes.d.ts +345 -0
  140. package/dist/src/query/jq/shapes.d.ts.map +1 -0
  141. package/dist/src/query/jq/shapes.js +584 -0
  142. package/dist/src/query/jq/shapes.js.map +1 -0
  143. package/dist/src/query/jq/spans.d.ts +133 -0
  144. package/dist/src/query/jq/spans.d.ts.map +1 -0
  145. package/dist/src/query/jq/spans.js +195 -0
  146. package/dist/src/query/jq/spans.js.map +1 -0
  147. package/dist/src/query/jq/split.d.ts +334 -0
  148. package/dist/src/query/jq/split.d.ts.map +1 -0
  149. package/dist/src/query/jq/split.js +2108 -0
  150. package/dist/src/query/jq/split.js.map +1 -0
  151. package/dist/src/query/jq/strftime.d.ts +20 -0
  152. package/dist/src/query/jq/strftime.d.ts.map +1 -0
  153. package/dist/src/query/jq/strftime.js +65 -0
  154. package/dist/src/query/jq/strftime.js.map +1 -0
  155. package/dist/src/query/jq/summary.d.ts +139 -0
  156. package/dist/src/query/jq/summary.d.ts.map +1 -0
  157. package/dist/src/query/jq/summary.js +222 -0
  158. package/dist/src/query/jq/summary.js.map +1 -0
  159. package/dist/src/query/jq/translate-builtins.d.ts +21 -0
  160. package/dist/src/query/jq/translate-builtins.d.ts.map +1 -0
  161. package/dist/src/query/jq/translate-builtins.js +1873 -0
  162. package/dist/src/query/jq/translate-builtins.js.map +1 -0
  163. package/dist/src/query/jq/translate.d.ts +627 -0
  164. package/dist/src/query/jq/translate.d.ts.map +1 -0
  165. package/dist/src/query/jq/translate.js +3364 -0
  166. package/dist/src/query/jq/translate.js.map +1 -0
  167. package/dist/src/query/types.d.ts +505 -0
  168. package/dist/src/query/types.d.ts.map +1 -0
  169. package/dist/src/query/types.js +231 -0
  170. package/dist/src/query/types.js.map +1 -0
  171. package/dist/src/runner_exec.d.ts +134 -0
  172. package/dist/src/runner_exec.d.ts.map +1 -0
  173. package/dist/src/runner_exec.js +371 -0
  174. package/dist/src/runner_exec.js.map +1 -0
  175. package/dist/src/runner_exec.spec.d.ts +6 -0
  176. package/dist/src/runner_exec.spec.d.ts.map +1 -0
  177. package/dist/src/runner_exec.spec.js +198 -0
  178. package/dist/src/runner_exec.spec.js.map +1 -0
  179. package/dist/src/runner_io.d.ts +370 -0
  180. package/dist/src/runner_io.d.ts.map +1 -0
  181. package/dist/src/runner_io.js +563 -0
  182. package/dist/src/runner_io.js.map +1 -0
  183. package/dist/src/runner_io.spec.d.ts +6 -0
  184. package/dist/src/runner_io.spec.d.ts.map +1 -0
  185. package/dist/src/runner_io.spec.js +224 -0
  186. package/dist/src/runner_io.spec.js.map +1 -0
  187. package/dist/src/runner_merge.d.ts +95 -0
  188. package/dist/src/runner_merge.d.ts.map +1 -0
  189. package/dist/src/runner_merge.js +238 -0
  190. package/dist/src/runner_merge.js.map +1 -0
  191. package/dist/src/runner_protocol.d.ts +11 -4
  192. package/dist/src/runner_protocol.d.ts.map +1 -1
  193. package/dist/src/runner_protocol.js +11 -4
  194. package/dist/src/runner_protocol.js.map +1 -1
  195. package/dist/src/serialization/beast2/index.d.ts +1 -1
  196. package/dist/src/serialization/beast2/index.d.ts.map +1 -1
  197. package/dist/src/serialization/beast2/index.js.map +1 -1
  198. package/dist/src/serialization/beast2/v5/frames.d.ts +10 -6
  199. package/dist/src/serialization/beast2/v5/frames.d.ts.map +1 -1
  200. package/dist/src/serialization/beast2/v5/frames.js +10 -6
  201. package/dist/src/serialization/beast2/v5/frames.js.map +1 -1
  202. package/dist/src/serialization/beast2/v5/frames.spec.d.ts +6 -0
  203. package/dist/src/serialization/beast2/v5/frames.spec.d.ts.map +1 -0
  204. package/dist/src/serialization/beast2/v5/frames.spec.js +42 -0
  205. package/dist/src/serialization/beast2/v5/frames.spec.js.map +1 -0
  206. package/dist/src/serialization/beast2/v5/index.spec.js +108 -0
  207. package/dist/src/serialization/beast2/v5/index.spec.js.map +1 -1
  208. package/dist/src/serialization/beast2/v5/lazy.d.ts +12 -7
  209. package/dist/src/serialization/beast2/v5/lazy.d.ts.map +1 -1
  210. package/dist/src/serialization/beast2/v5/lazy.js +16 -6
  211. package/dist/src/serialization/beast2/v5/lazy.js.map +1 -1
  212. package/dist/src/serialization/beast2/v5/lazy.spec.js +159 -18
  213. package/dist/src/serialization/beast2/v5/lazy.spec.js.map +1 -1
  214. package/dist/src/serialization/beast2/v5/stream.d.ts +110 -21
  215. package/dist/src/serialization/beast2/v5/stream.d.ts.map +1 -1
  216. package/dist/src/serialization/beast2/v5/stream.js +153 -42
  217. package/dist/src/serialization/beast2/v5/stream.js.map +1 -1
  218. package/dist/src/serialization/beast2/v5/weight.d.ts +36 -0
  219. package/dist/src/serialization/beast2/v5/weight.d.ts.map +1 -0
  220. package/dist/src/serialization/beast2/v5/weight.js +238 -0
  221. package/dist/src/serialization/beast2/v5/weight.js.map +1 -0
  222. package/dist/src/serialization/crc32.d.ts +38 -0
  223. package/dist/src/serialization/crc32.d.ts.map +1 -0
  224. package/dist/src/serialization/crc32.js +70 -0
  225. package/dist/src/serialization/crc32.js.map +1 -0
  226. package/dist/src/serialization/crc32.spec.d.ts +6 -0
  227. package/dist/src/serialization/crc32.spec.d.ts.map +1 -0
  228. package/dist/src/serialization/crc32.spec.js +92 -0
  229. package/dist/src/serialization/crc32.spec.js.map +1 -0
  230. package/dist/src/serialization/east-inferred.spec.js +4 -0
  231. package/dist/src/serialization/east-inferred.spec.js.map +1 -1
  232. package/dist/src/serialization/east.d.ts.map +1 -1
  233. package/dist/src/serialization/east.js +134 -110
  234. package/dist/src/serialization/east.js.map +1 -1
  235. package/dist/src/serialization/east.spec.js +185 -4
  236. package/dist/src/serialization/east.spec.js.map +1 -1
  237. package/dist/src/serialization/east_text.d.ts +25 -0
  238. package/dist/src/serialization/east_text.d.ts.map +1 -0
  239. package/dist/src/serialization/east_text.js +29 -0
  240. package/dist/src/serialization/east_text.js.map +1 -0
  241. package/dist/src/serialization/index.d.ts +1 -1
  242. package/dist/src/serialization/index.d.ts.map +1 -1
  243. package/dist/src/types.d.ts +1 -1
  244. package/dist/src/types.d.ts.map +1 -1
  245. package/dist/src/types.js +7 -6
  246. package/dist/src/types.js.map +1 -1
  247. package/package.json +6 -3
@@ -4,8 +4,9 @@
4
4
  */
5
5
  import { BooleanType, FloatType, IntegerType, StringType } from "../../types.js";
6
6
  import { Expr } from "../expr.js";
7
+ import { lazyLibrary } from "./lazy.js";
7
8
  /** Standard library functions for floats */
8
- export default {
9
+ export default lazyLibrary({
9
10
  /**
10
11
  * Checks if two floats are approximately equal within an epsilon tolerance.
11
12
  *
@@ -24,10 +25,12 @@ export default {
24
25
  * compiled(1.0, 1.1, 0.05); // false
25
26
  * ```
26
27
  */
27
- approxEqual: Expr.function([FloatType, FloatType, FloatType], BooleanType, ($, x, y, epsilon) => {
28
- const diff = $.let(x.subtract(y).abs());
29
- $.return(Expr.lessEqual(diff, epsilon));
30
- }),
28
+ get approxEqual() {
29
+ return Expr.function([FloatType, FloatType, FloatType], BooleanType, ($, x, y, epsilon) => {
30
+ const diff = $.let(x.subtract(y).abs());
31
+ $.return(Expr.lessEqual(diff, epsilon));
32
+ });
33
+ },
31
34
  /**
32
35
  * Rounds a float down to the nearest integer (floor).
33
36
  *
@@ -44,12 +47,14 @@ export default {
44
47
  * compiled(-2.3); // -3n
45
48
  * ```
46
49
  */
47
- roundFloor: Expr.function([FloatType], IntegerType, ($, x) => {
48
- const rem = $.let(x.remainder(1.0));
49
- const is_exact = $.let(Expr.equal(rem, 0.0).bitOr(Expr.equal(rem, -0.0)));
50
- const floored_float = $.let(is_exact.ifElse(() => x, () => Expr.greaterEqual(x, 0.0).ifElse(() => x.subtract(rem), () => x.subtract(rem).subtract(1.0))));
51
- $.return(floored_float.toInteger());
52
- }),
50
+ get roundFloor() {
51
+ return Expr.function([FloatType], IntegerType, ($, x) => {
52
+ const rem = $.let(x.remainder(1.0));
53
+ const is_exact = $.let(Expr.equal(rem, 0.0).bitOr(Expr.equal(rem, -0.0)));
54
+ const floored_float = $.let(is_exact.ifElse(() => x, () => Expr.greaterEqual(x, 0.0).ifElse(() => x.subtract(rem), () => x.subtract(rem).subtract(1.0))));
55
+ $.return(floored_float.toInteger());
56
+ });
57
+ },
53
58
  /**
54
59
  * Rounds a float up to the nearest integer (ceiling).
55
60
  *
@@ -66,13 +71,15 @@ export default {
66
71
  * compiled(-2.7); // -2n
67
72
  * ```
68
73
  */
69
- roundCeil: Expr.function([FloatType], IntegerType, ($, x) => {
70
- // Use the step-based roundUp with step=1.0, then convert
71
- const rem = $.let(x.remainder(1.0));
72
- const is_exact = $.let(Expr.equal(rem, 0.0).bitOr(Expr.equal(rem, -0.0)));
73
- const ceiled_float = $.let(is_exact.ifElse(() => x, () => Expr.greaterEqual(x, 0.0).ifElse(() => x.subtract(rem).add(1.0), () => x.subtract(rem))));
74
- $.return(ceiled_float.toInteger());
75
- }),
74
+ get roundCeil() {
75
+ return Expr.function([FloatType], IntegerType, ($, x) => {
76
+ // Use the step-based roundUp with step=1.0, then convert
77
+ const rem = $.let(x.remainder(1.0));
78
+ const is_exact = $.let(Expr.equal(rem, 0.0).bitOr(Expr.equal(rem, -0.0)));
79
+ const ceiled_float = $.let(is_exact.ifElse(() => x, () => Expr.greaterEqual(x, 0.0).ifElse(() => x.subtract(rem).add(1.0), () => x.subtract(rem))));
80
+ $.return(ceiled_float.toInteger());
81
+ });
82
+ },
76
83
  /**
77
84
  * Rounds a float to the nearest integer using half-away-from-zero rounding.
78
85
  *
@@ -90,10 +97,12 @@ export default {
90
97
  * compiled(-2.5); // -3n
91
98
  * ```
92
99
  */
93
- roundHalf: Expr.function([FloatType], IntegerType, ($, x) => {
94
- const rounded_float = $.let(Expr.greaterEqual(x, 0.0).ifElse(() => x.add(0.5).subtract(x.add(0.5).remainder(1.0)), () => x.subtract(0.5).subtract(x.subtract(0.5).remainder(1.0))));
95
- $.return(rounded_float.toInteger());
96
- }),
100
+ get roundHalf() {
101
+ return Expr.function([FloatType], IntegerType, ($, x) => {
102
+ const rounded_float = $.let(Expr.greaterEqual(x, 0.0).ifElse(() => x.add(0.5).subtract(x.add(0.5).remainder(1.0)), () => x.subtract(0.5).subtract(x.subtract(0.5).remainder(1.0))));
103
+ $.return(rounded_float.toInteger());
104
+ });
105
+ },
97
106
  /**
98
107
  * Truncates a float towards zero (removes the fractional part).
99
108
  *
@@ -110,10 +119,12 @@ export default {
110
119
  * compiled(-2.7); // -2n
111
120
  * ```
112
121
  */
113
- roundTrunc: Expr.function([FloatType], IntegerType, ($, x) => {
114
- const truncated_float = $.let(x.subtract(x.remainder(1.0)));
115
- $.return(truncated_float.toInteger());
116
- }),
122
+ get roundTrunc() {
123
+ return Expr.function([FloatType], IntegerType, ($, x) => {
124
+ const truncated_float = $.let(x.subtract(x.remainder(1.0)));
125
+ $.return(truncated_float.toInteger());
126
+ });
127
+ },
117
128
  /**
118
129
  * Rounds a float to the nearest multiple of a step value.
119
130
  *
@@ -133,24 +144,26 @@ export default {
133
144
  * compiled(3.14159, 0.01); // 3.14
134
145
  * ```
135
146
  */
136
- roundNearest: Expr.function([FloatType, FloatType], FloatType, ($, x, step) => {
137
- // Check for NaN/Infinity
138
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
139
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
140
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
141
- $.if(Expr.equal(step, 0.0), $ => $.return(x));
142
- const abs_step = $.let(step.abs());
143
- const divisions = $.let(x.divide(abs_step));
144
- // Round to nearest integer multiple
145
- const rounded_divisions_float = $.let(Expr.greaterEqual(divisions, 0.0).ifElse(() => {
146
- const shifted = divisions.add(0.5);
147
- return shifted.subtract(shifted.remainder(1.0));
148
- }, () => {
149
- const shifted = divisions.subtract(0.5);
150
- return shifted.subtract(shifted.remainder(1.0));
151
- }));
152
- $.return(rounded_divisions_float.multiply(abs_step));
153
- }),
147
+ get roundNearest() {
148
+ return Expr.function([FloatType, FloatType], FloatType, ($, x, step) => {
149
+ // Check for NaN/Infinity
150
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
151
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
152
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
153
+ $.if(Expr.equal(step, 0.0), $ => $.return(x));
154
+ const abs_step = $.let(step.abs());
155
+ const divisions = $.let(x.divide(abs_step));
156
+ // Round to nearest integer multiple
157
+ const rounded_divisions_float = $.let(Expr.greaterEqual(divisions, 0.0).ifElse(() => {
158
+ const shifted = divisions.add(0.5);
159
+ return shifted.subtract(shifted.remainder(1.0));
160
+ }, () => {
161
+ const shifted = divisions.subtract(0.5);
162
+ return shifted.subtract(shifted.remainder(1.0));
163
+ }));
164
+ $.return(rounded_divisions_float.multiply(abs_step));
165
+ });
166
+ },
154
167
  /**
155
168
  * Rounds a float up to the next multiple of a step value (ceiling).
156
169
  *
@@ -170,22 +183,24 @@ export default {
170
183
  * compiled(3.14, 0.1); // 3.2
171
184
  * ```
172
185
  */
173
- roundUp: Expr.function([FloatType, FloatType], FloatType, ($, x, step) => {
174
- // Check for NaN/Infinity
175
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
176
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
177
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
178
- $.if(Expr.equal(step, 0.0), $ => $.return(x));
179
- const abs_step = $.let(step.abs());
180
- const divisions = $.let(x.divide(abs_step));
181
- const rem = $.let(divisions.remainder(1.0));
182
- // Check if already exact
183
- const is_exact = $.let(Expr.equal(rem, 0.0).bitOr(Expr.equal(rem, -0.0)));
184
- $.if(is_exact, $ => $.return(x));
185
- // Round up
186
- const ceiled = $.let(Expr.greaterEqual(x, 0.0).ifElse(() => divisions.subtract(rem).add(1.0), () => divisions.subtract(rem)));
187
- $.return(ceiled.multiply(abs_step));
188
- }),
186
+ get roundUp() {
187
+ return Expr.function([FloatType, FloatType], FloatType, ($, x, step) => {
188
+ // Check for NaN/Infinity
189
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
190
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
191
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
192
+ $.if(Expr.equal(step, 0.0), $ => $.return(x));
193
+ const abs_step = $.let(step.abs());
194
+ const divisions = $.let(x.divide(abs_step));
195
+ const rem = $.let(divisions.remainder(1.0));
196
+ // Check if already exact
197
+ const is_exact = $.let(Expr.equal(rem, 0.0).bitOr(Expr.equal(rem, -0.0)));
198
+ $.if(is_exact, $ => $.return(x));
199
+ // Round up
200
+ const ceiled = $.let(Expr.greaterEqual(x, 0.0).ifElse(() => divisions.subtract(rem).add(1.0), () => divisions.subtract(rem)));
201
+ $.return(ceiled.multiply(abs_step));
202
+ });
203
+ },
189
204
  /**
190
205
  * Rounds a float down to the previous multiple of a step value (floor).
191
206
  *
@@ -205,22 +220,24 @@ export default {
205
220
  * compiled(3.19, 0.1); // 3.1
206
221
  * ```
207
222
  */
208
- roundDown: Expr.function([FloatType, FloatType], FloatType, ($, x, step) => {
209
- // Check for NaN/Infinity
210
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
211
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
212
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
213
- $.if(Expr.equal(step, 0.0), $ => $.return(x));
214
- const abs_step = $.let(step.abs());
215
- const divisions = $.let(x.divide(abs_step));
216
- const rem = $.let(divisions.remainder(1.0));
217
- // Check if already exact
218
- const is_exact = $.let(Expr.equal(rem, 0.0).bitOr(Expr.equal(rem, -0.0)));
219
- $.if(is_exact, $ => $.return(x));
220
- // Round down
221
- const floored = $.let(Expr.greaterEqual(x, 0.0).ifElse(() => divisions.subtract(rem), () => divisions.subtract(rem).subtract(1.0)));
222
- $.return(floored.multiply(abs_step));
223
- }),
223
+ get roundDown() {
224
+ return Expr.function([FloatType, FloatType], FloatType, ($, x, step) => {
225
+ // Check for NaN/Infinity
226
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
227
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
228
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
229
+ $.if(Expr.equal(step, 0.0), $ => $.return(x));
230
+ const abs_step = $.let(step.abs());
231
+ const divisions = $.let(x.divide(abs_step));
232
+ const rem = $.let(divisions.remainder(1.0));
233
+ // Check if already exact
234
+ const is_exact = $.let(Expr.equal(rem, 0.0).bitOr(Expr.equal(rem, -0.0)));
235
+ $.if(is_exact, $ => $.return(x));
236
+ // Round down
237
+ const floored = $.let(Expr.greaterEqual(x, 0.0).ifElse(() => divisions.subtract(rem), () => divisions.subtract(rem).subtract(1.0)));
238
+ $.return(floored.multiply(abs_step));
239
+ });
240
+ },
224
241
  /**
225
242
  * Rounds a float towards zero to the nearest multiple of a step value (truncate).
226
243
  *
@@ -239,17 +256,19 @@ export default {
239
256
  * compiled(-17.9, 5.0); // -15.0
240
257
  * ```
241
258
  */
242
- roundTruncate: Expr.function([FloatType, FloatType], FloatType, ($, x, step) => {
243
- // Check for NaN/Infinity
244
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
245
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
246
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
247
- $.if(Expr.equal(step, 0.0), $ => $.return(x));
248
- const abs_step = $.let(step.abs());
249
- const divisions = $.let(x.divide(abs_step));
250
- const truncated = $.let(divisions.subtract(divisions.remainder(1.0)));
251
- $.return(truncated.multiply(abs_step));
252
- }),
259
+ get roundTruncate() {
260
+ return Expr.function([FloatType, FloatType], FloatType, ($, x, step) => {
261
+ // Check for NaN/Infinity
262
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
263
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
264
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
265
+ $.if(Expr.equal(step, 0.0), $ => $.return(x));
266
+ const abs_step = $.let(step.abs());
267
+ const divisions = $.let(x.divide(abs_step));
268
+ const truncated = $.let(divisions.subtract(divisions.remainder(1.0)));
269
+ $.return(truncated.multiply(abs_step));
270
+ });
271
+ },
253
272
  /**
254
273
  * Rounds a float to a specified number of decimal places.
255
274
  *
@@ -268,28 +287,30 @@ export default {
268
287
  * compiled(2.5, 0n); // 3.0
269
288
  * ```
270
289
  */
271
- roundToDecimals: Expr.function([FloatType, IntegerType], FloatType, ($, x, decimals) => {
272
- // Check for NaN/Infinity
273
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
274
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
275
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
276
- // Build multiplier as 10^decimals iteratively
277
- const remaining = $.let(decimals);
278
- const multiplier = $.let(1.0);
279
- $.while(Expr.greater(remaining, 0n), $ => {
280
- $.assign(multiplier, multiplier.multiply(10.0));
281
- $.assign(remaining, remaining.subtract(1n));
290
+ get roundToDecimals() {
291
+ return Expr.function([FloatType, IntegerType], FloatType, ($, x, decimals) => {
292
+ // Check for NaN/Infinity
293
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot round NaN"));
294
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot round Infinity"));
295
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot round -Infinity"));
296
+ // Build multiplier as 10^decimals iteratively
297
+ const remaining = $.let(decimals);
298
+ const multiplier = $.let(1.0);
299
+ $.while(Expr.greater(remaining, 0n), $ => {
300
+ $.assign(multiplier, multiplier.multiply(10.0));
301
+ $.assign(remaining, remaining.subtract(1n));
302
+ });
303
+ const scaled = $.let(x.multiply(multiplier));
304
+ const rounded = $.let(Expr.greaterEqual(scaled, 0.0).ifElse(() => {
305
+ const shifted = scaled.add(0.5);
306
+ return shifted.subtract(shifted.remainder(1.0));
307
+ }, () => {
308
+ const shifted = scaled.subtract(0.5);
309
+ return shifted.subtract(shifted.remainder(1.0));
310
+ }));
311
+ $.return(rounded.divide(multiplier));
282
312
  });
283
- const scaled = $.let(x.multiply(multiplier));
284
- const rounded = $.let(Expr.greaterEqual(scaled, 0.0).ifElse(() => {
285
- const shifted = scaled.add(0.5);
286
- return shifted.subtract(shifted.remainder(1.0));
287
- }, () => {
288
- const shifted = scaled.subtract(0.5);
289
- return shifted.subtract(shifted.remainder(1.0));
290
- }));
291
- $.return(rounded.divide(multiplier));
292
- }),
313
+ },
293
314
  /**
294
315
  * Formats a float with comma separators for thousands.
295
316
  *
@@ -309,55 +330,57 @@ export default {
309
330
  * compiled(-5432.1, 3n); // "-5,432.100"
310
331
  * ```
311
332
  */
312
- printCommaSeperated: Expr.function([FloatType, IntegerType], StringType, ($, x, decimals) => {
313
- // Check for NaN/Infinity
314
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
315
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
316
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
317
- const negative = $.let(Expr.less(x, 0.0));
318
- const abs_x = $.let(x.abs());
319
- // Build multiplier for rounding
320
- const remaining = $.let(decimals);
321
- const multiplier = $.let(1.0);
322
- $.while(Expr.greater(remaining, 0n), $ => {
323
- $.assign(multiplier, multiplier.multiply(10.0));
324
- $.assign(remaining, remaining.subtract(1n));
325
- });
326
- // Round and split
327
- const scaled = $.let(abs_x.multiply(multiplier));
328
- const shifted = $.let(scaled.add(0.5));
329
- const rounded_scaled_float = $.let(shifted.subtract(shifted.remainder(1.0)));
330
- const rounded_scaled = $.let(rounded_scaled_float.toInteger());
331
- const integer_part = $.let(rounded_scaled.divide(multiplier.toInteger()));
332
- const frac_part = $.let(rounded_scaled.remainder(multiplier.toInteger()));
333
- // Format integer with commas
334
- const int_with_commas = $.let(integer_part);
335
- const comma_ret = $.let("");
336
- $.while(Expr.greater(int_with_commas, 999n), $ => {
337
- const z = $.let(int_with_commas.remainder(1000n));
338
- $.if(Expr.less(z, 10n), $ => {
339
- $.assign(comma_ret, Expr.str `,00${z}${comma_ret}`);
340
- }).else($ => {
341
- $.if(Expr.less(z, 100n), $ => {
342
- $.assign(comma_ret, Expr.str `,0${z}${comma_ret}`);
333
+ get printCommaSeperated() {
334
+ return Expr.function([FloatType, IntegerType], StringType, ($, x, decimals) => {
335
+ // Check for NaN/Infinity
336
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
337
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
338
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
339
+ const negative = $.let(Expr.less(x, 0.0));
340
+ const abs_x = $.let(x.abs());
341
+ // Build multiplier for rounding
342
+ const remaining = $.let(decimals);
343
+ const multiplier = $.let(1.0);
344
+ $.while(Expr.greater(remaining, 0n), $ => {
345
+ $.assign(multiplier, multiplier.multiply(10.0));
346
+ $.assign(remaining, remaining.subtract(1n));
347
+ });
348
+ // Round and split
349
+ const scaled = $.let(abs_x.multiply(multiplier));
350
+ const shifted = $.let(scaled.add(0.5));
351
+ const rounded_scaled_float = $.let(shifted.subtract(shifted.remainder(1.0)));
352
+ const rounded_scaled = $.let(rounded_scaled_float.toInteger());
353
+ const integer_part = $.let(rounded_scaled.divide(multiplier.toInteger()));
354
+ const frac_part = $.let(rounded_scaled.remainder(multiplier.toInteger()));
355
+ // Format integer with commas
356
+ const int_with_commas = $.let(integer_part);
357
+ const comma_ret = $.let("");
358
+ $.while(Expr.greater(int_with_commas, 999n), $ => {
359
+ const z = $.let(int_with_commas.remainder(1000n));
360
+ $.if(Expr.less(z, 10n), $ => {
361
+ $.assign(comma_ret, Expr.str `,00${z}${comma_ret}`);
343
362
  }).else($ => {
344
- $.assign(comma_ret, Expr.str `,${z}${comma_ret}`);
363
+ $.if(Expr.less(z, 100n), $ => {
364
+ $.assign(comma_ret, Expr.str `,0${z}${comma_ret}`);
365
+ }).else($ => {
366
+ $.assign(comma_ret, Expr.str `,${z}${comma_ret}`);
367
+ });
345
368
  });
369
+ $.assign(int_with_commas, int_with_commas.divide(1000n));
346
370
  });
347
- $.assign(int_with_commas, int_with_commas.divide(1000n));
348
- });
349
- const int_str = $.let(Expr.str `${int_with_commas}${comma_ret}`);
350
- // Format fractional part with padding
351
- const frac_str = $.let(Expr.str `${frac_part}`);
352
- const padding_needed = $.let(decimals.subtract(frac_str.length()));
353
- const padding = $.let("");
354
- $.while(Expr.greater(padding_needed, 0n), $ => {
355
- $.assign(padding, Expr.str `0${padding}`);
356
- $.assign(padding_needed, padding_needed.subtract(1n));
371
+ const int_str = $.let(Expr.str `${int_with_commas}${comma_ret}`);
372
+ // Format fractional part with padding
373
+ const frac_str = $.let(Expr.str `${frac_part}`);
374
+ const padding_needed = $.let(decimals.subtract(frac_str.length()));
375
+ const padding = $.let("");
376
+ $.while(Expr.greater(padding_needed, 0n), $ => {
377
+ $.assign(padding, Expr.str `0${padding}`);
378
+ $.assign(padding_needed, padding_needed.subtract(1n));
379
+ });
380
+ const result = $.let(Expr.equal(decimals, 0n).ifElse(() => int_str, () => Expr.str `${int_str}.${padding}${frac_str}`));
381
+ $.return(negative.ifElse(() => Expr.str `-${result}`, () => result));
357
382
  });
358
- const result = $.let(Expr.equal(decimals, 0n).ifElse(() => int_str, () => Expr.str `${int_str}.${padding}${frac_str}`));
359
- $.return(negative.ifElse(() => Expr.str `-${result}`, () => result));
360
- }),
383
+ },
361
384
  /**
362
385
  * Formats a float as currency with comma separators and 2 decimal places.
363
386
  *
@@ -376,40 +399,42 @@ export default {
376
399
  * compiled(1000000); // "$1,000,000.00"
377
400
  * ```
378
401
  */
379
- printCurrency: Expr.function([FloatType], StringType, ($, x) => {
380
- // Check for NaN/Infinity
381
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
382
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
383
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
384
- const negative = $.let(Expr.less(x, 0.0));
385
- const abs_x = $.let(x.abs());
386
- // Round to cents
387
- const shifted = $.let(abs_x.multiply(100.0).add(0.5));
388
- const cents_total_float = $.let(shifted.subtract(shifted.remainder(1.0)));
389
- const cents_total = $.let(cents_total_float.toInteger());
390
- const dollars = $.let(cents_total.divide(100n));
391
- const cents = $.let(cents_total.remainder(100n));
392
- // Format dollars with commas
393
- const dollars_with_commas = $.let(dollars);
394
- const comma_ret = $.let("");
395
- $.while(Expr.greater(dollars_with_commas, 999n), $ => {
396
- const z = $.let(dollars_with_commas.remainder(1000n));
397
- $.if(Expr.less(z, 10n), $ => {
398
- $.assign(comma_ret, Expr.str `,00${z}${comma_ret}`);
399
- }).else($ => {
400
- $.if(Expr.less(z, 100n), $ => {
401
- $.assign(comma_ret, Expr.str `,0${z}${comma_ret}`);
402
+ get printCurrency() {
403
+ return Expr.function([FloatType], StringType, ($, x) => {
404
+ // Check for NaN/Infinity
405
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
406
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
407
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
408
+ const negative = $.let(Expr.less(x, 0.0));
409
+ const abs_x = $.let(x.abs());
410
+ // Round to cents
411
+ const shifted = $.let(abs_x.multiply(100.0).add(0.5));
412
+ const cents_total_float = $.let(shifted.subtract(shifted.remainder(1.0)));
413
+ const cents_total = $.let(cents_total_float.toInteger());
414
+ const dollars = $.let(cents_total.divide(100n));
415
+ const cents = $.let(cents_total.remainder(100n));
416
+ // Format dollars with commas
417
+ const dollars_with_commas = $.let(dollars);
418
+ const comma_ret = $.let("");
419
+ $.while(Expr.greater(dollars_with_commas, 999n), $ => {
420
+ const z = $.let(dollars_with_commas.remainder(1000n));
421
+ $.if(Expr.less(z, 10n), $ => {
422
+ $.assign(comma_ret, Expr.str `,00${z}${comma_ret}`);
402
423
  }).else($ => {
403
- $.assign(comma_ret, Expr.str `,${z}${comma_ret}`);
424
+ $.if(Expr.less(z, 100n), $ => {
425
+ $.assign(comma_ret, Expr.str `,0${z}${comma_ret}`);
426
+ }).else($ => {
427
+ $.assign(comma_ret, Expr.str `,${z}${comma_ret}`);
428
+ });
404
429
  });
430
+ $.assign(dollars_with_commas, dollars_with_commas.divide(1000n));
405
431
  });
406
- $.assign(dollars_with_commas, dollars_with_commas.divide(1000n));
432
+ const dollars_str = $.let(Expr.str `${dollars_with_commas}${comma_ret}`);
433
+ const cents_str = $.let(Expr.less(cents, 10n).ifElse(() => Expr.str `0${cents}`, () => Expr.str `${cents}`));
434
+ const result = $.let(Expr.str `${dollars_str}.${cents_str}`);
435
+ $.return(negative.ifElse(() => Expr.str `-$${result}`, () => Expr.str `$${result}`));
407
436
  });
408
- const dollars_str = $.let(Expr.str `${dollars_with_commas}${comma_ret}`);
409
- const cents_str = $.let(Expr.less(cents, 10n).ifElse(() => Expr.str `0${cents}`, () => Expr.str `${cents}`));
410
- const result = $.let(Expr.str `${dollars_str}.${cents_str}`);
411
- $.return(negative.ifElse(() => Expr.str `-$${result}`, () => Expr.str `$${result}`));
412
- }),
437
+ },
413
438
  /**
414
439
  * Formats a float with a fixed number of decimal places.
415
440
  *
@@ -429,38 +454,40 @@ export default {
429
454
  * compiled(-0.5, 1n); // "-0.5"
430
455
  * ```
431
456
  */
432
- printFixed: Expr.function([FloatType, IntegerType], StringType, ($, x, decimals) => {
433
- // Check for NaN/Infinity
434
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
435
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
436
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
437
- const negative = $.let(Expr.less(x, 0.0));
438
- const abs_x = $.let(x.abs());
439
- // Build multiplier
440
- const remaining = $.let(decimals);
441
- const multiplier = $.let(1.0);
442
- $.while(Expr.greater(remaining, 0n), $ => {
443
- $.assign(multiplier, multiplier.multiply(10.0));
444
- $.assign(remaining, remaining.subtract(1n));
445
- });
446
- // Round and split
447
- const scaled = $.let(abs_x.multiply(multiplier));
448
- const shifted = $.let(scaled.add(0.5));
449
- const rounded_scaled_float = $.let(shifted.subtract(shifted.remainder(1.0)));
450
- const rounded_scaled = $.let(rounded_scaled_float.toInteger());
451
- const integer_part = $.let(rounded_scaled.divide(multiplier.toInteger()));
452
- const frac_part = $.let(rounded_scaled.remainder(multiplier.toInteger()));
453
- // Format fractional part with padding
454
- const frac_str = $.let(Expr.str `${frac_part}`);
455
- const padding_needed = $.let(decimals.subtract(frac_str.length()));
456
- const padding = $.let("");
457
- $.while(Expr.greater(padding_needed, 0n), $ => {
458
- $.assign(padding, Expr.str `0${padding}`);
459
- $.assign(padding_needed, padding_needed.subtract(1n));
457
+ get printFixed() {
458
+ return Expr.function([FloatType, IntegerType], StringType, ($, x, decimals) => {
459
+ // Check for NaN/Infinity
460
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
461
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
462
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
463
+ const negative = $.let(Expr.less(x, 0.0));
464
+ const abs_x = $.let(x.abs());
465
+ // Build multiplier
466
+ const remaining = $.let(decimals);
467
+ const multiplier = $.let(1.0);
468
+ $.while(Expr.greater(remaining, 0n), $ => {
469
+ $.assign(multiplier, multiplier.multiply(10.0));
470
+ $.assign(remaining, remaining.subtract(1n));
471
+ });
472
+ // Round and split
473
+ const scaled = $.let(abs_x.multiply(multiplier));
474
+ const shifted = $.let(scaled.add(0.5));
475
+ const rounded_scaled_float = $.let(shifted.subtract(shifted.remainder(1.0)));
476
+ const rounded_scaled = $.let(rounded_scaled_float.toInteger());
477
+ const integer_part = $.let(rounded_scaled.divide(multiplier.toInteger()));
478
+ const frac_part = $.let(rounded_scaled.remainder(multiplier.toInteger()));
479
+ // Format fractional part with padding
480
+ const frac_str = $.let(Expr.str `${frac_part}`);
481
+ const padding_needed = $.let(decimals.subtract(frac_str.length()));
482
+ const padding = $.let("");
483
+ $.while(Expr.greater(padding_needed, 0n), $ => {
484
+ $.assign(padding, Expr.str `0${padding}`);
485
+ $.assign(padding_needed, padding_needed.subtract(1n));
486
+ });
487
+ const result = $.let(Expr.equal(decimals, 0n).ifElse(() => Expr.str `${integer_part}`, () => Expr.str `${integer_part}.${padding}${frac_str}`));
488
+ $.return(negative.ifElse(() => Expr.str `-${result}`, () => result));
460
489
  });
461
- const result = $.let(Expr.equal(decimals, 0n).ifElse(() => Expr.str `${integer_part}`, () => Expr.str `${integer_part}.${padding}${frac_str}`));
462
- $.return(negative.ifElse(() => Expr.str `-${result}`, () => result));
463
- }),
490
+ },
464
491
  /**
465
492
  * Formats a float in compact form with business unit suffixes.
466
493
  *
@@ -482,44 +509,46 @@ export default {
482
509
  * compiled(3140000000); // "3.14B"
483
510
  * ```
484
511
  */
485
- printCompact: Expr.function([FloatType], StringType, ($, x) => {
486
- // Check for NaN/Infinity
487
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
488
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
489
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
490
- const negative = $.let(Expr.less(x, 0.0));
491
- const y = $.let(x.abs());
492
- $.if(Expr.less(y, 1000.0), $ => {
493
- const shifted = $.let(y.add(0.5));
512
+ get printCompact() {
513
+ return Expr.function([FloatType], StringType, ($, x) => {
514
+ // Check for NaN/Infinity
515
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
516
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
517
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
518
+ const negative = $.let(Expr.less(x, 0.0));
519
+ const y = $.let(x.abs());
520
+ $.if(Expr.less(y, 1000.0), $ => {
521
+ const shifted = $.let(y.add(0.5));
522
+ const rounded_int = $.let(shifted.subtract(shifted.remainder(1.0)));
523
+ const rounded = $.let(rounded_int.divide(100.0));
524
+ $.return(negative.ifElse(() => Expr.str `-${rounded}`, () => Expr.str `${rounded}`));
525
+ });
526
+ const scale = $.let(1n);
527
+ const scaled = $.let(y);
528
+ $.while(Expr.greaterEqual(scaled, 1000000.0), $ => {
529
+ $.assign(scaled, scaled.divide(1000.0));
530
+ $.assign(scale, scale.add(1n));
531
+ });
532
+ const suffix = $.let(Expr.equal(scale, 1n).ifElse(() => "K", () => Expr.equal(scale, 2n).ifElse(() => "M", () => Expr.equal(scale, 3n).ifElse(() => "B", () => Expr.equal(scale, 4n).ifElse(() => "T", () => Expr.equal(scale, 5n).ifElse(() => "Q", () => "Qi"))))));
533
+ const div = $.let(scaled.divide(1000.0));
534
+ $.if(Expr.greaterEqual(scaled, 100000.0), $ => {
535
+ const shifted = $.let(div.add(0.5));
536
+ const rounded_float = $.let(shifted.subtract(shifted.remainder(1.0)));
537
+ const rounded = $.let(rounded_float.toInteger());
538
+ $.return(negative.ifElse(() => Expr.str `-${rounded}${suffix}`, () => Expr.str `${rounded}${suffix}`));
539
+ });
540
+ $.if(Expr.greaterEqual(scaled, 10000.0), $ => {
541
+ const shifted = $.let(div.multiply(10.0).add(0.5));
542
+ const rounded_int = $.let(shifted.subtract(shifted.remainder(1.0)));
543
+ const rounded = $.let(rounded_int.divide(10.0));
544
+ $.return(negative.ifElse(() => Expr.str `-${rounded}${suffix}`, () => Expr.str `${rounded}${suffix}`));
545
+ });
546
+ const shifted = $.let(div.multiply(100.0).add(0.5));
494
547
  const rounded_int = $.let(shifted.subtract(shifted.remainder(1.0)));
495
548
  const rounded = $.let(rounded_int.divide(100.0));
496
- $.return(negative.ifElse(() => Expr.str `-${rounded}`, () => Expr.str `${rounded}`));
497
- });
498
- const scale = $.let(1n);
499
- const scaled = $.let(y);
500
- $.while(Expr.greaterEqual(scaled, 1000000.0), $ => {
501
- $.assign(scaled, scaled.divide(1000.0));
502
- $.assign(scale, scale.add(1n));
503
- });
504
- const suffix = $.let(Expr.equal(scale, 1n).ifElse(() => "K", () => Expr.equal(scale, 2n).ifElse(() => "M", () => Expr.equal(scale, 3n).ifElse(() => "B", () => Expr.equal(scale, 4n).ifElse(() => "T", () => Expr.equal(scale, 5n).ifElse(() => "Q", () => "Qi"))))));
505
- const div = $.let(scaled.divide(1000.0));
506
- $.if(Expr.greaterEqual(scaled, 100000.0), $ => {
507
- const shifted = $.let(div.add(0.5));
508
- const rounded_float = $.let(shifted.subtract(shifted.remainder(1.0)));
509
- const rounded = $.let(rounded_float.toInteger());
510
549
  $.return(negative.ifElse(() => Expr.str `-${rounded}${suffix}`, () => Expr.str `${rounded}${suffix}`));
511
550
  });
512
- $.if(Expr.greaterEqual(scaled, 10000.0), $ => {
513
- const shifted = $.let(div.multiply(10.0).add(0.5));
514
- const rounded_int = $.let(shifted.subtract(shifted.remainder(1.0)));
515
- const rounded = $.let(rounded_int.divide(10.0));
516
- $.return(negative.ifElse(() => Expr.str `-${rounded}${suffix}`, () => Expr.str `${rounded}${suffix}`));
517
- });
518
- const shifted = $.let(div.multiply(100.0).add(0.5));
519
- const rounded_int = $.let(shifted.subtract(shifted.remainder(1.0)));
520
- const rounded = $.let(rounded_int.divide(100.0));
521
- $.return(negative.ifElse(() => Expr.str `-${rounded}${suffix}`, () => Expr.str `${rounded}${suffix}`));
522
- }),
551
+ },
523
552
  /**
524
553
  * Formats a float as a percentage.
525
554
  *
@@ -541,24 +570,26 @@ export default {
541
570
  * compiled(-0.123, 2n); // "-12.30%"
542
571
  * ```
543
572
  */
544
- printPercentage: Expr.function([FloatType, IntegerType], StringType, ($, x, decimals) => {
545
- // Check for NaN/Infinity
546
- $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
547
- $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
548
- $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
549
- const percentage = $.let(x.multiply(100.0));
550
- // Build multiplier
551
- const remaining = $.let(decimals);
552
- const multiplier = $.let(1.0);
553
- $.while(Expr.greater(remaining, 0n), $ => {
554
- $.assign(multiplier, multiplier.multiply(10.0));
555
- $.assign(remaining, remaining.subtract(1n));
573
+ get printPercentage() {
574
+ return Expr.function([FloatType, IntegerType], StringType, ($, x, decimals) => {
575
+ // Check for NaN/Infinity
576
+ $.if(Expr.equal(x, NaN), $ => $.error("Cannot format NaN"));
577
+ $.if(Expr.equal(x, Infinity), $ => $.error("Cannot format Infinity"));
578
+ $.if(Expr.equal(x, -Infinity), $ => $.error("Cannot format -Infinity"));
579
+ const percentage = $.let(x.multiply(100.0));
580
+ // Build multiplier
581
+ const remaining = $.let(decimals);
582
+ const multiplier = $.let(1.0);
583
+ $.while(Expr.greater(remaining, 0n), $ => {
584
+ $.assign(multiplier, multiplier.multiply(10.0));
585
+ $.assign(remaining, remaining.subtract(1n));
586
+ });
587
+ const scaled = $.let(percentage.multiply(multiplier));
588
+ const shifted = $.let(Expr.greaterEqual(scaled, 0.0).ifElse(() => scaled.add(0.5), () => scaled.subtract(0.5)));
589
+ const rounded_int = $.let(shifted.subtract(shifted.remainder(1.0)));
590
+ const rounded = $.let(rounded_int.divide(multiplier));
591
+ $.return(Expr.str `${rounded}%`);
556
592
  });
557
- const scaled = $.let(percentage.multiply(multiplier));
558
- const shifted = $.let(Expr.greaterEqual(scaled, 0.0).ifElse(() => scaled.add(0.5), () => scaled.subtract(0.5)));
559
- const rounded_int = $.let(shifted.subtract(shifted.remainder(1.0)));
560
- const rounded = $.let(rounded_int.divide(multiplier));
561
- $.return(Expr.str `${rounded}%`);
562
- }),
563
- };
593
+ },
594
+ });
564
595
  //# sourceMappingURL=float.js.map