(n: BigDecimal): OrderingDetermines the sign of a given BigDecimal.
When to use
Use to classify a BigDecimal as negative, zero, or positive.
Example (Reading decimal signs)
import { BigDecimal } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigDecimal.sign(BigDecimal.fromStringUnsafe("-5")), -1)
assert.deepStrictEqual(BigDecimal.sign(BigDecimal.fromStringUnsafe("0")), 0)
assert.deepStrictEqual(BigDecimal.sign(BigDecimal.fromStringUnsafe("5")), 1)math
Source effect/BigDecimal.ts:10121 lines
export const const sign: (n: BigDecimal) => OrderingDetermines the sign of a given BigDecimal.
When to use
Use to classify a BigDecimal as negative, zero, or positive.
Example (Reading decimal signs)
import { BigDecimal } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigDecimal.sign(BigDecimal.fromStringUnsafe("-5")), -1)
assert.deepStrictEqual(BigDecimal.sign(BigDecimal.fromStringUnsafe("0")), 0)
assert.deepStrictEqual(BigDecimal.sign(BigDecimal.fromStringUnsafe("5")), 1)
sign = (n: BigDecimal(parameter) n: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
n: BigDecimal): 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 => n: BigDecimal(parameter) n: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
n.BigDecimal.value: bigintvalue === const bigint0: bigintbigint0 ? 0 : n: BigDecimal(parameter) n: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
n.BigDecimal.value: bigintvalue < const bigint0: bigintbigint0 ? -1 : 1Referenced by 1 symbols