~/bend-docscommunity

src/num.bend checks

raw source on the hub · import bend-toon-codec@0.1.0.0/src/num.bend as Num

2 imports
import Base
import ./head.bend as Hd

Types

type Sp source · line 15 · raw

Data

type Num source · line 20 · raw

Data

A parsed number: sign, integer digits, fraction digits, exponent as a biased-free signed pair.

type Sp2 source · line 23 · raw

Data

Definitions

def bias source · line 26 · raw

U32

def sp.cons source · line 29 · raw

@+c:U32 -> @+r:Sp -> Sp

def sp.pick source · line 34 · raw

@+d:Bool -> @+c:U32 -> @+whole:String -> @+r:Sp -> Sp

def span_digits source · line 42 · raw

@+s:String -> Sp

Leading run of ASCII digits, and the rest.

def is_zero_char source · line 49 · raw

@+c:Char -> Bool

def all_zeros source · line 53 · raw

@+s:String -> Bool

True when the string is empty or all zeros.

def num.opt source · line 60 · raw

@+ok:Bool -> @+n:Num -> Maybe<&2, Num>

def exp.done source · line 68 · raw

@+neg:Bool -> @+ip:String -> @+fp:String -> @+eneg:Bool -> @+r:Sp -> Maybe<&2, Num>

After the exponent digits: nothing may follow.

def exp.sign source · line 73 · raw

@+neg:Bool -> @+ip:String -> @+fp:String -> @+eneg:Bool -> @+s:String -> Maybe<&2, Num>

def exp.part.pick source · line 76 · raw

@+plus:Bool -> @+minus:Bool -> @+neg:Bool -> @+ip:String -> @+fp:String -> @+s:String -> Maybe<&2, Num>

def exp.part source · line 86 · raw

@+neg:Bool -> @+ip:String -> @+fp:String -> @+s:String -> Maybe<&2, Num>

After e: an optional sign, then digits.

def frac.rest.pick source · line 89 · raw

@+empty:Bool -> @+e:Bool -> @+neg:Bool -> @+ip:String -> @+fp:String -> @+s:String -> Maybe<&2, Num>

def frac.rest source · line 99 · raw

@+neg:Bool -> @+ip:String -> @+fp:String -> @+s:String -> Maybe<&2, Num>

After the fraction: end of text or an exponent.

def frac.digits source · line 102 · raw

@+neg:Bool -> @+ip:String -> @+r:Sp -> Maybe<&2, Num>

def int.rest.pick source · line 111 · raw

@+dot:Bool -> @+neg:Bool -> @+ip:String -> @+s:String -> Maybe<&2, Num>

def int.rest source · line 119 · raw

@+neg:Bool -> @+ip:String -> @+s:String -> Maybe<&2, Num>

After the integer digits: a fraction, an exponent, or the end.

def int.digits source · line 122 · raw

@+neg:Bool -> @+r:Sp -> Maybe<&2, Num>

def split.pick source · line 131 · raw

@+minus:Bool -> @+s:String -> Maybe<&2, Num>

def split source · line 139 · raw

@+s:String -> Maybe<&2, Num>

-?digits(.digits)?([eE][+-]?digits)?, as parts.

def zeros source · line 144 · raw

@+k:U32 -> String

def len32 source · line 147 · raw

@+s:String -> U32

def lead.pick source · line 150 · raw

@+z:Bool -> @+d:String -> @+p:U32 -> @+r:Sp2 -> Sp2

def strip.lead source · line 158 · raw

@+d:String -> @+p:U32 -> Sp2

Drop leading zeros of the digit string; each one lowers the point position.

def drop.pick source · line 165 · raw

@+z:Bool -> @+s:String -> @+rest:String -> String

def drop_zeros source · line 172 · raw

@+s:String -> String

def strip.trail source · line 179 · raw

@+d:String -> String

def mantissa source · line 182 · raw

@+d:String -> String

def exp.sign.text source · line 193 · raw

@+pos:Bool -> @+bp:U32 -> String

def fmt.exp source · line 201 · raw

@+bp:U32 -> @+d:String -> String

Exponent form: 1e+21, 1.5e-7. p is the point position, biased.

def fmt.small source · line 205 · raw

@+bp:U32 -> @+d:String -> String

0.000ddd for a point position of 0 down to -5.

def fmt.int.pick source · line 208 · raw

@+fits:Bool -> @+k:U32 -> @+d:String -> String

def fmt.int source · line 215 · raw

@+bp:U32 -> @+d:String -> String

def fmt.mid source · line 218 · raw

@+le0:Bool -> @+bp:U32 -> @+d:String -> String

def fmt.low source · line 225 · raw

@+exp:Bool -> @+bp:U32 -> @+d:String -> String

def fmt source · line 233 · raw

@+bp:U32 -> @+d:String -> String

Digits (no leading or trailing zeros) and biased point position to text.

def sign.text source · line 236 · raw

@+neg:Bool -> String

def exp.val.pick source · line 243 · raw

@+m:Maybe<&2, U32> -> U32

def exp.val source · line 250 · raw

@+s:String -> U32

def read.exp source · line 253 · raw

@+eneg:Bool -> @+ex:String -> U32

def canon.zero source · line 260 · raw

@+z:Bool -> @+neg:Bool -> @+d:String -> @+p:U32 -> String

def canon.digits source · line 267 · raw

@+neg:Bool -> @+s:Sp2 -> String

def canon.parts source · line 272 · raw

@+ok:Bool -> @+neg:Bool -> @+ip:String -> @+fp:String -> @+eneg:Bool -> @+ex:String -> Maybe<&2, String>

def canon.opt source · line 279 · raw

@+m:Maybe<&2, Num> -> Maybe<&2, String>

def canon source · line 287 · raw

@+s:String -> Maybe<&2, String>

Canonical text of a decimal number, None when s is not one.