Skip to content

Commit ec2a49b

Browse files
authored
Merge pull request #665 from Cormac-Williams/imp-fix
Add Fix function.
2 parents 099c1d6 + 509f0ba commit ec2a49b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/runtime/providers/math.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ class Round extends ValueOnlyConstraint {
328328
}
329329
}
330330

331+
class Fix extends ValueOnlyConstraint {
332+
getReturnValue(args) {
333+
let x = args[0];
334+
return x - x % 1;
335+
}
336+
}
337+
331338
class ToFixed extends TotalFunctionConstraint {
332339
static AttributeMapping = {
333340
"value": 0,
@@ -476,6 +483,7 @@ providers.provide("pow", Pow);
476483
providers.provide("random", Random);
477484
providers.provide("range", Range);
478485
providers.provide("round", Round);
486+
providers.provide("fix", Fix);
479487
providers.provide("gaussian", Gaussian);
480488
providers.provide("to-fixed", ToFixed);
481489

test/math.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,20 @@ let round_list : valueTest[] = [
214214
]
215215
testSingleExpressionByList(round_list);
216216

217-
// Test Round Function
217+
// Test To Fixed Function
218218
let toFixed_list : valueTest[] = [
219219
{expression: "to-fixed[ value: 1.499 places: 2 ]", expectedValue: 1.50},
220220
]
221221
testSingleExpressionByList(toFixed_list );
222222

223+
// Test Fix Function
224+
let Fix_list : valueTest[] = [
225+
{expression: "fix[ value: 1.99999999999999]", expectedValue: 1},
226+
{expression: "fix[ value: -1.99999999999999]", expectedValue: -1},
227+
]
228+
testSingleExpressionByList(Fix_list );
229+
230+
223231
test("Test that string concatenation is still working after NaN change.", (assert) => {
224232
let expected = {
225233
insert: [

0 commit comments

Comments
 (0)