Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3500 #3846

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

* [JS/TS] Fixed BigInt.ToDecimal with negative values (#3500) (by @ncave)

## 4.19.1 - 2024-06-13

### Fixed
Expand Down
7 changes: 4 additions & 3 deletions src/fable-library-ts/BigInt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ export function toFloat32(x: bigint): float32 { return Number(x); }
export function toFloat64(x: bigint): float64 { return Number(x); }

export function toDecimal(x: bigint): decimal {
const low = Number(BigInt.asUintN(32, x))
const mid = Number(BigInt.asUintN(32, x >> 32n))
const high = Number(BigInt.asUintN(32, x >> 64n))
const isNegative = x < zero;
const bits = abs(x);
const low = Number(BigInt.asUintN(32, bits));
const mid = Number(BigInt.asUintN(32, bits >> 32n));
const high = Number(BigInt.asUintN(32, bits >> 64n));
const scale = 0;
return fromParts(low, mid, high, isNegative, scale)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Js/Main/ConvertTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,14 @@ let tests =
let value = 1.0m
decimal (bigint value) |> equal value

testCase "BigInt ToDecimal with Decimal.MinValue works" <| fun () ->
let value = Decimal.MinValue
decimal (bigint value) |> equal value

testCase "BigInt ToDecimal with Decimal.MaxValue works" <| fun () ->
let value = Decimal.MaxValue
decimal (bigint value) |> equal value

testCase "BigInt ToString works" <| fun () ->
let value = 1234567890
string (bigint value) |> equal "1234567890"
Expand Down
10 changes: 10 additions & 0 deletions tests/Python/TestConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,16 @@ let ``test BigInt ToDecimal works`` () =
let value = 1.0m
decimal (bigint value) |> equal value

[<Fact>]
let ``test BigInt ToDecimal with Decimal.MinValue works`` () =
let value = Decimal.MinValue
decimal (bigint value) |> equal value

[<Fact>]
let ``test BigInt ToDecimal with Decimal.MaxValue works`` () =
let value = Decimal.MaxValue
decimal (bigint value) |> equal value

[<Fact>]
let ``test BigInt ToString works`` () =
let value = 1234567890
Expand Down
10 changes: 10 additions & 0 deletions tests/Rust/tests/src/ConvertTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,16 @@ let ``BigInt ToDecimal works`` () =
let value = 1.0m
decimal (bigint value) |> equal value

[<Fact>]
let ``BigInt ToDecimal with Decimal.MinValue works`` () =
let value = Decimal.MinValue
decimal (bigint value) |> equal value

[<Fact>]
let ``BigInt ToDecimal with Decimal.MaxValue works`` () =
let value = Decimal.MaxValue
decimal (bigint value) |> equal value

[<Fact>]
let ``BigInt ToString works`` () =
let value = 1234567890
Expand Down
Loading