(n: bigint): OrderingDetermines the sign of a given bigint.
When to use
Use to classify a bigint as negative, zero, or positive.
Example (Determining bigint signs)
import { BigInt } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigInt.sign(-5n), -1)
assert.deepStrictEqual(BigInt.sign(0n), 0)
assert.deepStrictEqual(BigInt.sign(5n), 1)math
Source effect/BigInt.ts:5771 lines
export const const sign: (n: bigint) => OrderingDetermines the sign of a given bigint.
When to use
Use to classify a bigint as negative, zero, or positive.
Example (Determining bigint signs)
import { BigInt } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigInt.sign(-5n), -1)
assert.deepStrictEqual(BigInt.sign(0n), 0)
assert.deepStrictEqual(BigInt.sign(5n), 1)
sign = (n: bigintn: bigint): type Ordering = 0 | 1 | -1Represents the result of comparing two values.
When to use
Use to model a normalized comparison result that is exactly less than,
equal to, or greater than.
Details
-1 indicates the first value is less than the second
0 indicates the values are equal
1 indicates the first value is greater than the second
Example (Defining comparison results)
import type { Ordering } from "effect"
// Custom comparison function
const compareNumbers = (a: number, b: number): Ordering.Ordering => {
if (a < b) return -1
if (a > b) return 1
return 0
}
console.log(compareNumbers(5, 10)) // -1 (5 < 10)
console.log(compareNumbers(10, 5)) // 1 (10 > 5)
console.log(compareNumbers(5, 5)) // 0 (5 == 5)
// Using with string comparison
const compareStrings = (a: string, b: string): Ordering.Ordering => {
return a.localeCompare(b) as Ordering.Ordering
}
Ordering => import orderorder.const BigInt: Order<bigint>Order instance for bigints that compares them numerically.
When to use
Use when you need numeric ordering for bigint values.
Details
Uses standard numeric comparison for bigint values and handles arbitrarily
large integers.
Example (Ordering BigInts)
import { Order } from "effect"
console.log(Order.BigInt(1n, 2n)) // -1
console.log(Order.BigInt(2n, 1n)) // 1
console.log(Order.BigInt(1n, 1n)) // 0
BigInt(n: bigintn, const bigint0: bigintbigint0)