-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support pow for integers * Add a changelog
- Loading branch information
1 parent
7e2870b
commit 48658e2
Showing
5 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
### Added | ||
|
||
## [5.2.0] - 2023-10-25 | ||
|
||
### Added | ||
|
||
- `pow` for raising a decimal to a power (#43) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Decimal128 } from "../src/decimal128.mjs"; | ||
|
||
describe("pow", () => { | ||
test("throws if not an integer", () => { | ||
expect(() => { | ||
new Decimal128("1.2").pow(new Decimal128("2.3")); | ||
}).toThrow(); | ||
}); | ||
test("pow zero is one", () => { | ||
expect( | ||
new Decimal128("42.456").pow(new Decimal128("0")).toString() | ||
).toStrictEqual("1"); | ||
}); | ||
test("negative power", () => { | ||
expect( | ||
new Decimal128("5.6").pow(new Decimal128("-2")).toString() | ||
).toStrictEqual("0.031887755102040816326530612244898"); | ||
}); | ||
test("positive power", () => { | ||
expect( | ||
new Decimal128("5.6").pow(new Decimal128("8")).toString() | ||
).toStrictEqual("967173.11574016"); | ||
}); | ||
describe("infinity", () => { | ||
test("positive infinity", () => { | ||
expect( | ||
new Decimal128("Infinity").pow(new Decimal128("2")).toString() | ||
).toStrictEqual("Infinity"); | ||
}); | ||
test("negative infinity squared", () => { | ||
expect( | ||
new Decimal128("-Infinity").pow(new Decimal128("2")).toString() | ||
).toStrictEqual("Infinity"); | ||
}); | ||
test("negative infinity cubed", () => { | ||
expect( | ||
new Decimal128("-Infinity").pow(new Decimal128("3")).toString() | ||
).toStrictEqual("-Infinity"); | ||
}); | ||
}); | ||
describe("NaN", () => { | ||
expect(() => new Decimal128("42").pow("NaN")).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Decimal128 } from "../src/decimal128.mjs"; | ||
|
||
describe("reciprocal", () => { | ||
test("divide by zero", () => { | ||
expect(new Decimal128("0").reciprocal().toString()).toStrictEqual( | ||
"NaN" | ||
); | ||
}); | ||
test("one divided by one", () => { | ||
expect(new Decimal128("1").reciprocal().toString()).toStrictEqual("1"); | ||
}); | ||
test("one divided by two", () => { | ||
expect(new Decimal128("2").reciprocal().toString()).toStrictEqual( | ||
"0.5" | ||
); | ||
}); | ||
test("reciprocal of point two", () => { | ||
expect(new Decimal128("0.2").reciprocal().toString()).toStrictEqual( | ||
"5" | ||
); | ||
}); | ||
test("receiprocal of three", () => { | ||
expect(new Decimal128("3").reciprocal().toString()).toStrictEqual( | ||
"0.3333333333333333333333333333333333" | ||
); | ||
}); | ||
test("reciprocal of point three", () => { | ||
expect(new Decimal128("0.3").reciprocal().toString()).toStrictEqual( | ||
"3.333333333333333333333333333333333" | ||
); | ||
}); | ||
test("NaN", () => { | ||
expect(new Decimal128("NaN").reciprocal().toString()).toStrictEqual( | ||
"NaN" | ||
); | ||
}); | ||
test("positive infinity", () => { | ||
expect( | ||
new Decimal128("Infinity").reciprocal().toString() | ||
).toStrictEqual("0"); | ||
}); | ||
test("negative infinity", () => { | ||
expect( | ||
new Decimal128("-Infinity").reciprocal().toString() | ||
).toStrictEqual("-0"); | ||
}); | ||
}); |