Numbers and Safe Arithmetic
Blorp keeps numeric behavior explicit: default arithmetic is infallible, and checked helpers model failure.
Int
Int is the default whole-number type.
int.brp
count: Int = 42Float
Float is the default floating-point type.
float.brp
ratio: Float = 0.75Sized Numbers
Use Int8, UInt8, Int32, Float32, and related types when size is part of the contract.
sized.brp
byte: UInt8 = to_uint8(255)
small: Int32 = to_int32(42)Wrapping Defaults
Integer overflow wraps, and integer division or modulo by zero returns 0 by default.
wrapping.brp
wrapped: UInt8 = to_uint8(255) + to_uint8(1)Checked Helpers
Use helpers such as divide_checked, add_checked, or mod_checked when a failure value matters.
checked.brp
import:
int: divide_checked
match divide_checked(10, 0):
Ok(n): print(n.to_string())
Err(_): print("cannot divide")Example
numbers.brp
import:
int: divide_checked
func main(args: List[String]) -> Void:
byte: UInt8 = to_uint8(255)
flags: UInt8 = bit_or(to_uint8(1), shift_left(to_uint8(1), 3))
match divide_checked(10, 0):
Ok(value): print(value.to_string())
Err(_): print("cannot divide")
print(byte.to_string())
print(flags.to_string())
Try It
terminal
blorp run numbers.brp