Capy-Bearer Documentation

s64

lib call

Capy

function s64(value : as string, opt : any = {}) s64

s64() converts the exact text from value. It uses base 10 unless opt.base selects another integer base. opt.fallback is the result for empty text or text that does not parse. It defaults to 0.

value accepts scalar values through as string. The conversion keeps scalar text exact. Empty and missing any values both convert to empty text. Use value? before conversion when presence matters. An empty value is present, but a missing value is not.

The options map accepts only fallback and base. An unknown key is an error.

A one-argument numeric conversion uses the number directly. A float truncates toward zero. An out-of-range or nonfinite input produces 0.

Text parsing trims surrounding whitespace and accepts a leading +. In base 10, decimal fractions and exponents are valid and truncate toward zero. Other bases require integer digits without prefixes such as 0x. The base must be a numeric whole value from 2 through 36. Out-of-range text uses the fallback.

Add fallback: when zero must not hide invalid input. For example, s64("3.9", fallback: -1) returns 3, not -1.

print(s64("2a", base: 16, fallback: -1), "\n")

Output

42

Parameters

value : scalar value or text to convert

opt : options map with fallback and base

Return Values

A signed 64-bit integer, or opt.fallback.