Num.dec.exact: def of yaml-for-bend@0.1.1.0 Import: import yaml-for-bend@0.1.1.0/num.bend as Num Lines 195-211 of yaml-for-bend@0.1.1.0/num.bend: https://jend.leeeet.dev/read.txt?path=yaml-for-bend@0.1.1.0/num.bend&start_line=195&end_line=211 import Base # 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. def dec.exact(+s: String) -> String: +neg = String.starts_with(s, "-") +body = Bool.pick(String, Bool.or(neg, String.starts_with(s, "+")), String.drop(s, 1n), s) +ip = take.digits(body) +fp = take.digits(after.dot(body)) +e = exp.read(after.e(body)) +all = ip ++ fp +lead = Nat.sub(String.length(all), String.length(drop.zeros(all))) +ds = strip.end.zeros(drop.zeros(all)) +point = Nat.sub(point.at(String.length(ip), e), lead) +sign = Bool.pick(String, neg, "-", "") when(String, Bool.and(Bool.not(String.is_empty(ds)), Nat.is_gt(point, Nat.add(dec.off(), 309n))), u => sign ++ ".inf", u => when(String, Bool.or(String.is_empty(ds), Nat.is_lt(Nat.add(point, 330n), dec.off())), u => sign ++ "0.0", u => sign ++ dec.place(ds, point, dec.off()))) Uses (24): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.not https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.or https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.pick https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.is_gt https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.is_lt https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.drop https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.is_empty https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.length https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.starts_with https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=after.dot https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=after.e https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=dec.off https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=dec.place https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=drop.zeros https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=exp.read https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=point.at https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=strip.end.zeros https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=take.digits https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/num.bend&name=when