format.bend checks
raw source on the hub · import bend-float64@0.1.7.0/format.bend as Format
bend-float64's fixed-digit formatting, as Python's % operator does it: fixed(x, n) is '%.nf', sci(x, n) is '%.ne', general(x, n) is '%.ng'. Any number of digits; the digits are those of the exact binary value, rounded half to even, computed with big integers (no approximation). Pure.
5 imports
import Base import ./wide.bend as W import ./big.bend as B import ./float64.bend as F import ./text.bend as T
Types
type Way source · line 32 · raw
Data
WExactWay
WShiftWay
WDivWay
type Sig source · line 125 · raw
Data
n + 1 significant digits of m 2^q, and the decimal exponent x of the first: the exponent estimate x0 (from the shortest digits; it can be one off near a power of ten) is corrected while the digit count is wrong
Sig@x:U32 -> @r:List<&2, U32> -> Sig
type GL source · line 171 · raw
Data
%g's three shapes: 0.000ddd (x from -4 to -1), ddd.ddd (x from 0 to p - 1), d.ddde+xx
GSmallGL
GFixedGL
GSciGL
type Fmt source · line 193 · raw
Data
KFixedFmt
KSciFmt
KGenFmt
Definitions
def is_neg source · line 10 · raw
@+x:U32 -> Bool
def round_shift source · line 16 · raw
@+num:List<&2, U32> -> @+k:U32 -> List<&2, U32>
(num / 2^k) rounded half to even, k > 0
def round_qr source · line 22 · raw
@r:0xf7ad0261e36ff1404423df221623a9ba/big.QR -> @+den:List<&2, U32> -> List<&2, U32>
def round_div source · line 29 · raw
@+num:List<&2, U32> -> @+den:List<&2, U32> -> List<&2, U32>
(num / den) rounded half to even, den > 1
def scaled_way source · line 37 · raw
@w:Way -> @+m:List<&2, U32> -> @+q:U32 -> @+s:U32 -> List<&2, U32>
def scaled source · line 48 · raw
@+m:List<&2, U32> -> @+q:U32 -> @+s:U32 -> List<&2, U32>
m 2^q 10^s rounded half to even to an integer (q, s signed)
def ds_q source · line 53 · raw
@d:0xf7ad0261e36ff1404423df221623a9ba/big.DS -> List<&2, U32>
def ds_r source · line 58 · raw
@d:0xf7ad0261e36ff1404423df221623a9ba/big.DS -> U32
def four source · line 63 · raw
@+r:U32 -> List<&2, U32>
def chunks source · line 67 · raw
@n:Nat -> @+xs:List<&2, U32> -> @+acc:List<&2, U32> -> List<&2, U32>
xs's digits, four at a time from the bottom, most significant first (with leading zeros)
def nonempty source · line 76 · raw
@ds:List<&2, U32> -> List<&2, U32>
the decimal digits of xs, most significant first, no leading zeros ([0] for 0)
def digits source · line 83 · raw
@+xs:List<&2, U32> -> List<&2, U32>
def pad source · line 87 · raw
@n:Nat -> @ds:List<&2, U32> -> List<&2, U32>
n zeros then ds
def sign_str source · line 96 · raw
@+neg:Bool -> String
def zeros source · line 99 · raw
@+n:U32 -> String
def dstr source · line 102 · raw
@ds:List<&2, U32> -> String
def point_at source · line 106 · raw
@+ds:List<&2, U32> -> @+n:U32 -> String
ds (at least n + 1 digits) with a point before the last n
def pad_go source · line 111 · raw
@enough:Bool -> @+ds:List<&2, U32> -> @+n:U32 -> @+l:U32 -> List<&2, U32>
the digits of R, padded with zeros on the left to n + 1 at least
def padded source · line 118 · raw
@+r:List<&2, U32> -> @+n:U32 -> List<&2, U32>
def sig_pick source · line 128 · raw
@c:Cmp -> @+x:U32 -> @+r:List<&2, U32> -> @more:(@_:U32 -> Sig) -> Sig
def sig_go source · line 137 · raw
@fuel:Nat -> @+m:List<&2, U32> -> @+q:U32 -> @+n:U32 -> @+x:U32 -> Sig
def decpt source · line 145 · raw
@d:0xf7ad0261e36ff1404423df221623a9ba/text.Digits -> U32
def sig source · line 150 · raw
@+e:U32 -> @+m:0xf7ad0261e36ff1404423df221623a9ba/wide.W64 -> @+n:U32 -> Sig
def exp_part source · line 153 · raw
@+x:U32 -> String
def sci_sig source · line 156 · raw
@s:Sig -> @+n:U32 -> String
def strip_frac source · line 162 · raw
@+ds:List<&2, U32> -> List<&2, U32>
without trailing zeros after the point, nor the point if nothing is left after it
def g_point source · line 165 · raw
@+ds:List<&2, U32> -> @+k:U32 -> String
def g_lay source · line 176 · raw
@g:GL -> @+ds:List<&2, U32> -> @+x:U32 -> String
def gen_sig source · line 186 · raw
@s:Sig -> @+p:U32 -> String
%g with p significant digits: fixed when -4 <= x < p, else scientific; trailing zeros dropped
def zero_text source · line 198 · raw
@k:Fmt -> @+neg:Bool -> @+n:U32 -> String
def fin_text source · line 207 · raw
@k:Fmt -> @+neg:Bool -> @+e:U32 -> @+m:0xf7ad0261e36ff1404423df221623a9ba/wide.W64 -> @+n:U32 -> String
def text_c source · line 217 · raw
@c:0xf7ad0261e36ff1404423df221623a9ba/float64.Cls -> @+k:Fmt -> @+n:U32 -> String
def fixed source · line 229 · raw
@x:0xf7ad0261e36ff1404423df221623a9ba/float64.F64 -> @+n:U32 -> String
Python's '%.nf' % x: n digits after the point (none, and no point, for n = 0), rounded half to even
def sci source · line 234 · raw
@x:0xf7ad0261e36ff1404423df221623a9ba/float64.F64 -> @+n:U32 -> String
Python's '%.ne' % x: one digit, a point and n more (no point for n = 0), then e, a sign and at least two exponent digits
def general source · line 239 · raw
@x:0xf7ad0261e36ff1404423df221623a9ba/float64.F64 -> @+n:U32 -> String
Python's '%.ng' % x: n significant digits (1 for n = 0), fixed when the exponent is from -4 up to below n, else scientific, with trailing zeros (and a bare point) dropped