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

Commit 4f5ee87

Browse files
committed
WIP
1 parent 928aec2 commit 4f5ee87

38 files changed

+42
-404
lines changed

examples/bill.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../src/Decimal128.mjs";
22

33
const zero = new Decimal128("0");
44
const one = new Decimal128("1");

examples/currency.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../src/Decimal128.mjs";
22

33
let exchangeRateEurToUsd = new Decimal128("1.09");
44
let amountInUsd = new Decimal128("450.27");

examples/five-numbers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../src/Decimal128.mjs";
22

33
function getRandomInt(max: number): number {
44
return Math.floor(Math.random() * max);

examples/floor.mts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../src/Decimal128.mjs";
22

33
function floor(d: Decimal128): Decimal128 {
44
return d.round(0, "floor");

examples/midprice.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../src/Decimal128.mjs";
22

33
function getRandomInt(max: number): number {
44
return Math.floor(Math.random() * max);

examples/mortgage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../src/Decimal128.mjs";
22
import { pow } from "./pow.mjs";
33

44
const one = new Decimal128("1");

examples/pow.mts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../src/Decimal128.mjs";
22

33
function pow(a: Decimal128, b: number): Decimal128 {
44
let result = a;

examples/round.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Examples from the Intl.NumberFormat spec
44

5-
import { Decimal128 } from "../src/decimal128.mjs";
5+
import { Decimal128 } from "../src/Decimal128.mjs";
66

77
let minusOnePointFive = new Decimal128("-1.5");
88
let zeroPointFour = new Decimal128("0.4");

examples/rounding-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../src/Decimal128.mjs";
22

33
function getRandomInt(max: number): number {
44
return Math.floor(Math.random() * max);

examples/roundtrip.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
2-
31
function getRandomInt(max: number): number {
42
return Math.floor(Math.random() * max);
53
}

src/Decimal.mts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Rational } from "./rational.mjs";
1+
import { Rational } from "./Rational.mjs";
22

33
const ratOne = new Rational(1n, 1n);
44
const ratTen = new Rational(10n, 1n);

src/decimal128.mts src/Decimal128.mts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import { Digit, DigitOrTen, RoundingMode, ROUNDING_MODES } from "./common.mjs";
17-
import { Rational } from "./rational.mjs";
17+
import { Rational } from "./Rational.mjs";
1818
import { Decimal } from "./Decimal.mjs";
1919

2020
const EXPONENT_MIN = -6176;

src/rational.mts src/Rational.mts

File renamed without changes.

src/common.mts

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
import {
2-
ROUNDING_MODE_CEILING,
3-
ROUNDING_MODE_FLOOR,
4-
ROUNDING_MODE_HALF_EXPAND,
5-
ROUNDING_MODE_TRUNCATE,
6-
} from "./decimal128.mjs";
7-
81
/**
92
* Counts the number of significant digits in a digit string, assumed to be normalized.
103
*
@@ -36,10 +29,6 @@ export function countSignificantDigits(s: string): number {
3629
return s.length;
3730
}
3831

39-
export function countDigits(s: string): number {
40-
return s.replace(/[.]/, "").length;
41-
}
42-
4332
export function countFractionalDigits(s: string): number {
4433
let [, fractional] = s.split(".");
4534

@@ -53,6 +42,12 @@ export function countFractionalDigits(s: string): number {
5342
export type Digit = -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; // -1 signals that we're moving from the integer part to the decimal part of a decimal number
5443
export type DigitOrTen = Digit | 10;
5544

45+
const ROUNDING_MODE_CEILING = "ceil";
46+
const ROUNDING_MODE_FLOOR = "floor";
47+
const ROUNDING_MODE_TRUNCATE = "trunc";
48+
const ROUNDING_MODE_HALF_EVEN = "halfEven";
49+
const ROUNDING_MODE_HALF_EXPAND = "halfExpand";
50+
5651
export type RoundingMode =
5752
| "ceil"
5853
| "floor"
@@ -61,11 +56,11 @@ export type RoundingMode =
6156
| "halfExpand";
6257

6358
export const ROUNDING_MODES: RoundingMode[] = [
64-
"ceil",
65-
"floor",
66-
"trunc",
67-
"halfEven",
68-
"halfExpand",
59+
ROUNDING_MODE_CEILING,
60+
ROUNDING_MODE_FLOOR,
61+
ROUNDING_MODE_TRUNCATE,
62+
ROUNDING_MODE_HALF_EVEN,
63+
ROUNDING_MODE_HALF_EXPAND,
6964
];
7065

7166
function roundIt(

tests/abs.test.js tests/Decimal128/abs.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
const MAX_SIGNIFICANT_DIGITS = 34;
44
const bigDigits = "9".repeat(MAX_SIGNIFICANT_DIGITS);

tests/add.test.js tests/Decimal128/add.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
const MAX_SIGNIFICANT_DIGITS = 34;
44
const bigDigits = "9".repeat(MAX_SIGNIFICANT_DIGITS);

tests/constructor.test.js tests/Decimal128/constructor.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
const MAX_SIGNIFICANT_DIGITS = 34;
44

tests/divide.test.js tests/Decimal128/divide.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
describe("division", () => {
44
test("simple example", () => {

tests/equals.test.js tests/Decimal128/equals.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
const MAX_SIGNIFICANT_DIGITS = 34;
44
const nan = new Decimal128("NaN");
File renamed without changes.

tests/lessthan.test.js tests/Decimal128/lessthan.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
const MAX_SIGNIFICANT_DIGITS = 34;
44
const nan = new Decimal128("NaN");

tests/multiply.test.js tests/Decimal128/multiply.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
const examples = [
44
["123.456", "789.789", "97504.190784"],

tests/neg.test.js tests/Decimal128/neg.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
const MAX_SIGNIFICANT_DIGITS = 34;
44
const bigDigits = "9".repeat(MAX_SIGNIFICANT_DIGITS);

tests/remainder.test.js tests/Decimal128/remainder.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
const a = "4.1";
44
const b = "1.25";

tests/round.test.js tests/Decimal128/round.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22
import * as string_decoder from "string_decoder";
33
import { expectDecimal128 } from "./util.js";
44

File renamed without changes.

tests/subtract.test.js tests/Decimal128/subtract.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22
import { expectDecimal128 } from "./util.js";
33

44
const MAX_SIGNIFICANT_DIGITS = 34;

tests/tobigint.test.js tests/Decimal128/tobigint.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22
import { expectDecimal128 } from "./util.js";
33

44
describe("NaN", () => {

tests/toexponential.test.js tests/Decimal128/toexponential.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22
import { expectDecimal128 } from "./util.js";
33

44
describe("NaN", () => {

tests/tofixed.test.js tests/Decimal128/tofixed.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22
import { expectDecimal128 } from "./util.js";
33

44
describe("NaN", () => {

tests/tonumber.test.js tests/Decimal128/tonumber.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22
import { expectDecimal128 } from "./util.js";
33

44
describe("NaN", () => {

tests/toprecison.test.js tests/Decimal128/toprecison.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22
import { expectDecimal128 } from "./util.js";
33

44
describe("NaN", () => {

tests/tostring.test.js tests/Decimal128/tostring.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22
import { expectDecimal128 } from "./util.js";
33

44
describe("NaN", () => {

tests/util.js tests/Decimal128/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
export function expectDecimal128(a, b) {
44
let lhs = a instanceof Decimal128 ? a.toString({ normalize: false }) : a;

tests/valueof.test.js tests/Decimal128/valueof.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Decimal128 } from "../src/decimal128.mjs";
1+
import { Decimal128 } from "../../src/Decimal128.mjs";
22

33
describe("valueOf", () => {
44
test("throws unconditionally", () => {

tests/rational.test.js tests/Rational/rational.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Rational } from "../src/rational.mjs";
1+
import { Rational } from "../../src/Rational.mjs";
22
describe("constructor", () => {
33
test("cannot divide by zero", () => {
44
expect(() => new Rational(1n, 0n)).toThrow(RangeError);
File renamed without changes.

0 commit comments

Comments
 (0)