package core:strconv/decimal

⌘K
Ctrl+K
or
/

    Overview

    Multiple precision decimal numbers NOTE: This is only for floating point printing and nothing else

    Index

    Types (1)
    Constants (0)

    This section is empty.

    Variables (0)

    This section is empty.

    Procedure Groups (0)

    This section is empty.

    Types

    Decimal ¶

    Decimal :: struct {
    	digits:        [384]u8,
    	// big-endian digits
    	count:         int,
    	decimal_point: int,
    	neg:           bool,
    	trunc:         bool,
    }
    Related Procedures With Parameters

    Constants

    This section is empty.

    Variables

    This section is empty.

    Procedures

    assign ¶

    assign :: proc(a: ^Decimal, idx: u64) {…}
     

    Converts a given u64 integer idx to its Decimal representation in the provided Decimal struct.

    Used for internal Decimal Operations.

    Inputs
    a: Where the result will be stored idx: The value to be assigned to the Decimal

    can_round_up ¶

    can_round_up :: proc(a: ^Decimal, nd: int) -> bool {…}
     

    Determines if the Decimal can be rounded up at the given digit index

    Inputs
    a: The Decimal to check nd: The digit index to consider for rounding up

    Returns Boolean if can be rounded up at the given index (>=5)

    decimal_to_string ¶

    decimal_to_string :: proc(buf: []u8, a: ^Decimal) -> string {…}
     

    Converts a Decimal to a string representation, using the provided buffer as storage.

    Inputs
    buf: A byte slice buffer to hold the resulting string a: The struct to be converted to a string

    Returns
    A string representation of the Decimal

    println ¶

    println :: proc(.. args: ..any) {…}

    round ¶

    round :: proc(a: ^Decimal, nd: int) {…}
     

    Rounds the Decimal at the given digit index

    Inputs
    a: The Decimal to be modified nd: The digit index to round

    round_down ¶

    round_down :: proc(a: ^Decimal, nd: int) {…}
     

    Rounds down the decimal value to the specified number of decimal places

    Inputs
    a: The Decimal value to be rounded down nd: The number of decimal places to round down to

    Example:
    import "core:fmt"
    import "core:strconv/decimal"
    round_down_example :: proc() {
    	d: decimal.Decimal
    	str := [64]u8{}
    	ok := decimal.set(&d, "123.456")
    	decimal.round_down(&d, 5)
    	fmt.println(decimal.decimal_to_string(str[:], &d))
    }
    
    Output:
    123.45
    

    round_up ¶

    round_up :: proc(a: ^Decimal, nd: int) {…}
     

    Rounds the Decimal up at the given digit index

    Inputs
    a: The Decimal to be modified nd: The digit index to round up

    rounded_integer ¶

    rounded_integer :: proc(a: ^Decimal) -> u64 {…}
     

    Extracts the rounded integer part of a decimal value

    Inputs
    a: A pointer to the Decimal value to extract the rounded integer part from

    WARNING: There are no guarantees about overflow.

    Returns The rounded integer part of the input decimal value

    Example:
    import "core:fmt"
    import "core:strconv/decimal"
    rounded_integer_example :: proc() {
    	d: decimal.Decimal
    	ok := decimal.set(&d, "123.456")
    	fmt.println(decimal.rounded_integer(&d))
    }
    
    Output:
    123
    

    set ¶

    set :: proc(d: ^Decimal, s: string) -> (ok: bool) {…}
     

    Sets a Decimal from a given string s. The string is expected to represent a float. Stores parsed number in the given Decimal structure. If parsing fails, the Decimal will be left in an undefined state.

    Inputs
    d: Pointer to a Decimal struct where the parsed result will be stored s: The input string representing the floating-point number

    Returns
    ok: A boolean indicating whether the parsing was successful

    shift ¶

    shift :: proc(a: ^Decimal, i: int) {…}
     

    Shifts the decimal of the input value by the specified number of places

    Inputs
    a: The Decimal to be modified i: The number of places to shift the decimal (positive for left shift, negative for right shift)

    shift_left ¶

    shift_left :: proc(a: ^Decimal, k: uint) {…}
     

    Shifts the decimal of the input value to the left by k places

    WARNING: asserts k < 61

    Inputs
    a: The Decimal to be modified k: The number of places to shift the decimal to the left

    shift_right ¶

    shift_right :: proc(a: ^Decimal, k: uint) {…}
     

    Shifts the Decimal value to the right by k positions.

    Used for internal Decimal Operations.

    Inputs
    a: The Decimal struct to be shifted k: The number of positions to shift right

    trim ¶

    trim :: proc(a: ^Decimal) {…}
     

    Trims trailing zeros in the given Decimal, updating the count and decimal_point values as needed.

    Inputs
    a: Pointer to the Decimal struct to be trimmed

    Procedure Groups

    This section is empty.

    Source Files

    Generation Information

    Generated with odin version dev-2024-10 (vendor "odin") Windows_amd64 @ 2024-10-05 21:10:06.348036300 +0000 UTC