~/bend-docscommunity

num.bend checks

raw source on the hub · import yaml-for-bend@0.1.0.0/num.bend as Num

Numbers kept as text. Bend's Nat stops at 2^48, so an integer of any size is a list of decimal digits, and a float is exact decimal text.

1 import
import Base

Types

type Exp source · line 7 · raw

Data

The exponent after "e": its sign and digits, as an offset point shift.

Definitions

def when source · line 10 · raw

@-A:Type -> @hit:Bool -> @yes:(@_:Unit -> A) -> @no:(@_:Unit -> A) -> A

def code source · line 17 · raw

@c:Char -> U32

def digit source · line 23 · raw

@c:Char -> Nat

A digit's value, for digits up to base 36 ("a" and "A" are 10).

def digit.char source · line 27 · raw

@n:Nat -> Char

def big.chars source · line 36 · raw

@s:String -> List<&2, Nat>

def big.trim.go source · line 43 · raw

@ds:List<&2, Nat> -> List<&2, Nat>

def big.trim source · line 50 · raw

@ds:List<&2, Nat> -> List<&2, Nat>

def big.of.nat source · line 54 · raw

@+n:Nat -> List<&2, Nat>

A Nat that fits, as a big number.

def big.mul.add source · line 58 · raw

@ds:List<&2, Nat> -> @+base:Nat -> @carry:Nat -> List<&2, Nat>

+ds+ times +base+, plus +carry+.

def big.read source · line 67 · raw

@s:String -> @+base:Nat -> @acc:List<&2, Nat> -> List<&2, Nat>

The digits of +s+ in +base+ (each a digit of that base) as a big number.

def big.digits source · line 74 · raw

@ds:List<&2, Nat> -> String

def big.show source · line 81 · raw

@+ds:List<&2, Nat> -> String

def signed source · line 85 · raw

@+neg:Bool -> @+digits:String -> String

An integer's text: "-" when negative and not zero.

def int.text source · line 89 · raw

@+neg:Bool -> @s:String -> @+base:Nat -> String

+s+, digits of +base+, as decimal text with the sign.

def zeros source · line 95 · raw

@n:Nat -> String

def drop.zeros source · line 98 · raw

@s:String -> String

def take.digits source · line 109 · raw

@s:String -> String

def dec.place source · line 119 · raw

@+ds:String -> @+point:Nat -> @+off:Nat -> String

The decimal whose digits are +ds+ (no zeros at either end) with the point +point+ places from their left, written "12.5", "0.001" or "300.0". The point is offset by +off+ so it can be negative.

def dec.off source · line 128 · raw

Nat

Where a decimal's point is counted from, so it can go left of the digits; an exponent is capped below it.

def big.small source · line 131 · raw

@s:String -> @acc:Nat -> Nat

def exp.nat source · line 139 · raw

@+s:String -> Nat

Exponent digits as a Nat, capped past where a double ends (about 308).

def exp.read source · line 143 · raw

@s:String -> Exp

def after.e source · line 156 · raw

@s:String -> String

def after.dot source · line 169 · raw

@s:String -> String

def point.at source · line 180 · raw

@+ip:Nat -> @e:Exp -> Nat

def strip.end.zeros source · line 185 · raw

@s:String -> String

def dec.exact source · line 191 · raw

@+s:String -> String

The value of a decimal literal ("1_000.5" without the "_", ".5", "1.", "2.5e-3"), written exactly: "1000.5", "0.5", "1.0", "0.0025". Past what a double holds it is ".inf"; under, zero.