mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
initial
This commit is contained in:
@@ -9,7 +9,18 @@ Int_Flags :: bit_set[Int_Flag]
|
||||
MAX_BASE :: 32
|
||||
digits := "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
/*
|
||||
Determines whether the given unsigned 64-bit integer is a negative value by interpreting it as a signed integer with the specified bit size.
|
||||
|
||||
**Inputs**
|
||||
- x: The unsigned 64-bit integer to check for negativity
|
||||
- is_signed: A boolean indicating if the input should be treated as a signed integer
|
||||
- bit_size: The bit size of the signed integer representation (8, 16, 32, or 64)
|
||||
|
||||
**Returns**
|
||||
- u: The absolute value of the input integer
|
||||
- neg: A boolean indicating whether the input integer is negative
|
||||
*/
|
||||
is_integer_negative :: proc(x: u64, is_signed: bool, bit_size: int) -> (u: u64, neg: bool) {
|
||||
u = x
|
||||
if is_signed {
|
||||
@@ -36,7 +47,21 @@ is_integer_negative :: proc(x: u64, is_signed: bool, bit_size: int) -> (u: u64,
|
||||
}
|
||||
return
|
||||
}
|
||||
/*
|
||||
Appends the string representation of an integer to a buffer with specified base, flags, and digit set.
|
||||
|
||||
**Inputs**
|
||||
- buf: The buffer to append the integer representation to
|
||||
- x: The integer value to convert
|
||||
- base: The base for the integer representation (2 <= base <= MAX_BASE)
|
||||
- is_signed: A boolean indicating if the input should be treated as a signed integer
|
||||
- bit_size: The bit size of the signed integer representation (8, 16, 32, or 64)
|
||||
- digits: The digit set used for the integer representation
|
||||
- flags: The Int_Flags bit set to control integer formatting
|
||||
|
||||
**Returns**
|
||||
- The string containing the integer representation appended to the buffer
|
||||
*/
|
||||
append_bits :: proc(buf: []byte, x: u64, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flags) -> string {
|
||||
if base < 2 || base > MAX_BASE {
|
||||
panic("strconv: illegal base passed to append_bits")
|
||||
@@ -78,7 +103,18 @@ append_bits :: proc(buf: []byte, x: u64, base: int, is_signed: bool, bit_size: i
|
||||
copy(buf, out)
|
||||
return string(buf[0:len(out)])
|
||||
}
|
||||
/*
|
||||
Determines whether the given unsigned 128-bit integer is a negative value by interpreting it as a signed integer with the specified bit size.
|
||||
|
||||
**Inputs**
|
||||
- x: The unsigned 128-bit integer to check for negativity
|
||||
- is_signed: A boolean indicating if the input should be treated as a signed integer
|
||||
- bit_size: The bit size of the signed integer representation (8, 16, 32, 64, or 128)
|
||||
|
||||
**Returns**
|
||||
- u: The absolute value of the input integer
|
||||
- neg: A boolean indicating whether the input integer is negative
|
||||
*/
|
||||
is_integer_negative_128 :: proc(x: u128, is_signed: bool, bit_size: int) -> (u: u128, neg: bool) {
|
||||
u = x
|
||||
if is_signed {
|
||||
@@ -109,9 +145,21 @@ is_integer_negative_128 :: proc(x: u128, is_signed: bool, bit_size: int) -> (u:
|
||||
}
|
||||
return
|
||||
}
|
||||
/*
|
||||
Appends the string representation of a 128-bit integer to a buffer with specified base, flags, and digit set.
|
||||
|
||||
// import "core:runtime"
|
||||
**Inputs**
|
||||
- buf: The buffer to append the integer representation to
|
||||
- x: The 128-bit integer value to convert
|
||||
- base: The base for the integer representation (2 <= base <= MAX_BASE)
|
||||
- is_signed: A boolean indicating if the input should be treated as a signed integer
|
||||
- bit_size: The bit size of the signed integer representation (8, 16, 32, 64, or 128)
|
||||
- digits: The digit set used for the integer representation
|
||||
- flags: The Int_Flags bit set to control integer formatting
|
||||
|
||||
**Returns**
|
||||
- The string containing the integer representation appended to the buffer
|
||||
*/
|
||||
append_bits_128 :: proc(buf: []byte, x: u128, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flags) -> string {
|
||||
if base < 2 || base > MAX_BASE {
|
||||
panic("strconv: illegal base passed to append_bits")
|
||||
|
||||
Reference in New Issue
Block a user