Module

pooka/float

src/pooka/float.pooka

Floating-point numbers measure with a small, honest ruler.

Expose BEAM floating-point operations and fallible numeric conversions. Parsing, square roots and powers keep failure in Result; rounding operations return Int. These are floating-point calculations, so decimal identities need not be exact.

Pooka
import pooka/float

assert float.floor(-1.2) == -2

API reference

class

ParseError

src/pooka/float.pooka:20
class ParseError(text: String)

A float failure carrying the details needed by its caller. Keep this value in Result until a boundary can explain it.

field

text

src/pooka/float.pooka:20
text: String
INFERREDString
constructor

new

src/pooka/float.pooka:20
INFERREDfn(String) -> pooka/float.ParseError
class

MathError

src/pooka/float.pooka:24
class MathError(message: String)

A float failure carrying the details needed by its caller. Keep this value in Result until a boundary can explain it.

field

message

src/pooka/float.pooka:24
message: String
INFERREDString
constructor

new

src/pooka/float.pooka:24
INFERREDfn(String) -> pooka/float.MathError
function

parse

src/pooka/float.pooka:51
parse(text: String) -> Result(Float, ParseError)
INFERREDfn(String) -> Result(Float, pooka/float.ParseError)

Parse a floating-point value, retaining failure as ParseError.

Pooka
import pooka/float

assert float.parse("3.0") == Ok(3.0)
function

to_string

src/pooka/float.pooka:65
to_string(value: Float) -> String
INFERREDfn(Float) -> String

Render a floating-point value using the library's textual representation.

Pooka
import pooka/float

let text = float.to_string(3.0)
function

abs

src/pooka/float.pooka:76
abs(value: Float) -> Float
INFERREDfn(Float) -> Float

Return the nonnegative magnitude.

Pooka
import pooka/float

assert float.abs(-3.0) == 3.0
function

min

src/pooka/float.pooka:90
min(a: Float, b: Float) -> Float
INFERREDfn(Float, Float) -> Float

Return the smaller value.

Pooka
import pooka/float

assert float.min(2.0, 3.0) == 2.0
function

max

src/pooka/float.pooka:104
max(a: Float, b: Float) -> Float
INFERREDfn(Float, Float) -> Float

Return the larger value.

Pooka
import pooka/float

assert float.max(2.0, 3.0) == 3.0
function

clamp

src/pooka/float.pooka:118
clamp(value: Float, lower: Float, upper: Float) -> Float
INFERREDfn(Float, Float, Float) -> Float

Keep a value between the bounds; reversed bounds are normalized first.

Pooka
import pooka/float

assert float.clamp(3.0, -2.0, 2.0) == 2.0
function

floor

src/pooka/float.pooka:129
floor(value: Float) -> Int
INFERREDfn(Float) -> Int

Round downward toward negative infinity and return Int.

Pooka
import pooka/float

assert float.floor(-1.2) == -2
function

ceil

src/pooka/float.pooka:140
ceil(value: Float) -> Int
INFERREDfn(Float) -> Int

Round upward toward positive infinity and return Int.

Pooka
import pooka/float

assert float.ceil(-1.2) == -1
function

round

src/pooka/float.pooka:151
round(value: Float) -> Int
INFERREDfn(Float) -> Int

Round to the nearest integer using the runtime's rounding rule.

Pooka
import pooka/float

assert float.round(1.6) == 2
function

truncate

src/pooka/float.pooka:162
truncate(value: Float) -> Int
INFERREDfn(Float) -> Int

Discard the fractional part toward zero.

Pooka
import pooka/float

assert float.truncate(-1.8) == -1
function

sqrt

src/pooka/float.pooka:173
sqrt(value: Float) -> Result(Float, MathError)
INFERREDfn(Float) -> Result(Float, pooka/float.MathError)

Compute the square root, returning MathError for an unsupported domain.

Pooka
import pooka/float

assert float.sqrt(9.0) == Ok(3.0)
function

pow

src/pooka/float.pooka:187
pow(base: Float, exponent: Float) -> Result(Float, MathError)
INFERREDfn(Float, Float) -> Result(Float, pooka/float.MathError)

Compute a floating-point power, keeping runtime domain failures in Result.

Pooka
import pooka/float

assert float.pow(2.0, 3.0) == Ok(8.0)
function

is_finite

src/pooka/float.pooka:201
is_finite(value: Float) -> Bool
INFERREDfn(Float) -> Bool

Apply the library's finite-value predicate to a BEAM float.

Pooka
import pooka/float

assert float.is_finite(1.0)
function

is_nan

src/pooka/float.pooka:212
is_nan(value: Float) -> Bool
INFERREDfn(Float) -> Bool

Test whether the value fails self-equality.

Pooka
import pooka/float

assert !float.is_nan(1.0)