Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit ad01100

Browse files
committed
Rename total property to normalize
1 parent ebf82fe commit ad01100

File tree

4 files changed

+67
-69
lines changed

4 files changed

+67
-69
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [11.1.0] - 2024-03-29
11+
12+
### Changed
13+
14+
- For `lessThan` and `equals`: the property of the (optional) second argument `total` has been renamed to `normalize`
15+
1016
## [11.0.0] - 2024-03-26
1117

1218
### Added

src/decimal128.mts

+5-17
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ const DEFAULT_TOSTRING_OPTIONS: FullySpecifiedToStringOptions = Object.freeze({
880880
});
881881

882882
interface CmpOptions {
883-
total?: boolean;
883+
normalize?: boolean;
884884
}
885885

886886
interface FullySpecifiedCmpOptions {
@@ -968,8 +968,8 @@ function ensureFullySpecifiedCmpOptions(
968968
return opts;
969969
}
970970

971-
if ("boolean" === typeof options.total) {
972-
opts.total = options.total;
971+
if ("boolean" === typeof options.normalize) {
972+
opts.total = options.normalize;
973973
}
974974

975975
return opts;
@@ -1246,23 +1246,11 @@ export class Decimal128 {
12461246
}
12471247

12481248
lessThan(x: Decimal128, opts?: CmpOptions): boolean {
1249-
let resolvedOpts = { ...opts };
1250-
1251-
if (this.isNaN() || x.isNaN() || !this.isFinite() || !x.isFinite()) {
1252-
resolvedOpts.total = true;
1253-
}
1254-
1255-
return this.cmp(x, resolvedOpts) === -1;
1249+
return this.cmp(x, opts) === -1;
12561250
}
12571251

12581252
equals(x: Decimal128, opts?: CmpOptions): boolean {
1259-
let resolvedOpts = { ...opts };
1260-
1261-
if (this.isNaN() || x.isNaN() || !this.isFinite() || !x.isFinite()) {
1262-
resolvedOpts.total = true;
1263-
}
1264-
1265-
return this.cmp(x, resolvedOpts) === 0;
1253+
return this.cmp(x, opts) === 0;
12661254
}
12671255

12681256
abs(): Decimal128 {

tests/equals.test.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("equals", () => {
5757
expect(a.equals(b)).toStrictEqual(true);
5858
});
5959
test("take trailing zeroes into account", () => {
60-
expect(a.equals(b, { total: true })).toStrictEqual(false);
60+
expect(a.equals(b, { normalize: true })).toStrictEqual(false);
6161
});
6262
test("mathematically distinct", () => {
6363
expect(a.equals(c)).toStrictEqual(false);
@@ -88,12 +88,12 @@ describe("many digits", () => {
8888
});
8989
describe("NaN", () => {
9090
test("NaN equals NaN, even if total is false", () => {
91-
expect(nan.equals(nan)).toStrictEqual(true);
91+
expect(nan.equals(nan)).toStrictEqual(false);
9292
});
9393
test("NaN does equal NaN, with total comparison", () => {
9494
expect(
9595
nan.equals(nan, {
96-
total: true,
96+
normalize: true,
9797
})
9898
).toStrictEqual(true);
9999
});
@@ -103,7 +103,7 @@ describe("many digits", () => {
103103
test("number equals NaN fails, with total comparison", () => {
104104
expect(
105105
one.equals(nan, {
106-
total: true,
106+
normalize: true,
107107
})
108108
).toStrictEqual(false);
109109
});
@@ -113,7 +113,7 @@ describe("many digits", () => {
113113
test("NaN equals number is false, with total comparison", () => {
114114
expect(
115115
nan.equals(one, {
116-
total: true,
116+
normalize: true,
117117
})
118118
).toStrictEqual(false);
119119
});
@@ -170,10 +170,10 @@ describe("zero", () => {
170170
expect(negZero.equals(zero)).toStrictEqual(true);
171171
});
172172
test("negative zero vs zero, normalization disabled", () => {
173-
expect(negZero.equals(zero, { total: true })).toStrictEqual(false);
173+
expect(negZero.equals(zero, { normalize: true })).toStrictEqual(false);
174174
});
175175
test("zero vs negative zero, normalization disabled", () => {
176-
expect(zero.equals(negZero, { total: true })).toStrictEqual(false);
176+
expect(zero.equals(negZero, { normalize: true })).toStrictEqual(false);
177177
});
178178
});
179179

@@ -191,16 +191,16 @@ describe("normalization", () => {
191191
expect(d1.equals(d3)).toStrictEqual(true);
192192
});
193193
test("compare non-normal (1)", () => {
194-
expect(d1.equals(d2, { total: true })).toStrictEqual(false);
194+
expect(d1.equals(d2, { normalize: true })).toStrictEqual(false);
195195
});
196196
test("compare non-normal (2)", () => {
197-
expect(d2.equals(d1, { total: true })).toStrictEqual(false);
197+
expect(d2.equals(d1, { normalize: true })).toStrictEqual(false);
198198
});
199199
test("compare two non-normal values", () => {
200-
expect(d2.equals(d3, { total: true })).toStrictEqual(false);
200+
expect(d2.equals(d3, { normalize: true })).toStrictEqual(false);
201201
});
202202
test("compare two non-normal values", () => {
203-
expect(d3.equals(d2, { total: true })).toStrictEqual(false);
203+
expect(d3.equals(d2, { normalize: true })).toStrictEqual(false);
204204
});
205205
});
206206

@@ -241,99 +241,99 @@ describe("examples from the General Decimal Arithmetic specification", () => {
241241
test("example one", () => {
242242
expect(
243243
new Decimal128("12.73").equals(new Decimal128("127.9"), {
244-
total: true,
244+
normalize: true,
245245
})
246246
).toStrictEqual(false);
247247
});
248248
test("example two", () => {
249249
expect(
250250
new Decimal128("-127").equals(new Decimal128("12"), {
251-
total: true,
251+
normalize: true,
252252
})
253253
).toStrictEqual(false);
254254
});
255255
test("example three", () => {
256256
expect(
257257
new Decimal128("12.30").equals(new Decimal128("12.3"), {
258-
total: true,
258+
normalize: true,
259259
})
260260
).toStrictEqual(false);
261261
});
262262
test("example four", () => {
263263
expect(
264264
new Decimal128("12.30").equals(new Decimal128("12.30"), {
265-
total: true,
265+
normalize: true,
266266
})
267267
).toStrictEqual(true);
268268
});
269269
test("example five", () => {
270270
expect(
271271
new Decimal128("12.3").equals(new Decimal128("12.300"), {
272-
total: true,
272+
normalize: true,
273273
})
274274
).toStrictEqual(false);
275275
});
276276
test("example six", () => {
277277
expect(
278278
new Decimal128("12.3").equals(new Decimal128("NaN"), {
279-
total: true,
279+
normalize: true,
280280
})
281281
).toStrictEqual(false);
282282
});
283283
describe("inline examples", () => {
284284
test("example one", () => {
285285
expect(
286286
new Decimal128("-Infinity").equals(new Decimal128("-127"), {
287-
total: true,
287+
normalize: true,
288288
})
289289
).toStrictEqual(false);
290290
});
291291
test("example two", () => {
292292
expect(
293293
new Decimal128("-1.00").equals(new Decimal128("-1"), {
294-
total: true,
294+
normalize: true,
295295
})
296296
).toStrictEqual(false);
297297
});
298298
test("example three", () => {
299299
expect(
300300
new Decimal128("-0.000").equals(negZero, {
301-
total: true,
301+
normalize: true,
302302
})
303303
).toStrictEqual(false);
304304
});
305305
test("example four", () => {
306306
expect(
307307
negZero.equals(zero, {
308-
total: true,
308+
normalize: true,
309309
})
310310
).toStrictEqual(false);
311311
});
312312
test("example five", () => {
313313
expect(
314314
new Decimal128("1.2300").equals(new Decimal128("1.23"), {
315-
total: true,
315+
normalize: true,
316316
})
317317
).toStrictEqual(false);
318318
});
319319
test("example six", () => {
320320
expect(
321321
new Decimal128("1.23").equals(new Decimal128("1E+9"), {
322-
total: true,
322+
normalize: true,
323323
})
324324
).toStrictEqual(false);
325325
});
326326
test("example seven", () => {
327327
expect(
328328
new Decimal128("1E+9").equals(new Decimal128("Infinity"), {
329-
total: true,
329+
normalize: true,
330330
})
331331
).toStrictEqual(false);
332332
});
333333
test("example eight", () => {
334334
expect(
335335
new Decimal128("Infinity").equals(new Decimal128("NaN"), {
336-
total: true,
336+
normalize: true,
337337
})
338338
).toStrictEqual(false);
339339
});
@@ -345,6 +345,6 @@ describe("examples from a presentation at TC39 plenary", () => {
345345
test("NaN with a payload", () => {
346346
expect(
347347
new Decimal128("NaN").equals(new Decimal128("NaN123"))
348-
).toStrictEqual(true);
348+
).toStrictEqual(false);
349349
});
350350
});

0 commit comments

Comments
 (0)