[PATCH 1/5] Collect fltXYbfmt parameters into analogue of intparams
[Thread Prev] | [Thread Next]
- Subject: [PATCH 1/5] Collect fltXYbfmt parameters into analogue of intparams
- From: "S. Gilles" <sgilles@xxxxxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Mon, 9 Sep 2019 08:38:25 -0400
- To: "myrddin-dev" <myrddin-dev@xxxxxxxxxxxxxx>
- Cc: "S. Gilles" <sgilles@xxxxxxxxxxxx>
--- lib/std/fltfmt.myr | 17 +++++++++++------ lib/std/fmt.myr | 25 +++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/std/fltfmt.myr b/lib/std/fltfmt.myr index 6a51ef46..ee035520 100644 --- a/lib/std/fltfmt.myr +++ b/lib/std/fltfmt.myr @@ -14,14 +14,19 @@ pkg std = pkglocal const MAbsolute = 1 pkglocal const MRelative = 2 - pkglocal const flt64bfmt : (sb : strbuf#, val : flt64, mode : int, precision : int -> void) - pkglocal const flt32bfmt : (sb : strbuf#, val : flt32, mode : int, precision : int -> void) + pkglocal type fltparams = struct + mode : int + prec : int + ;; + + pkglocal const flt64bfmt : (sb : strbuf#, opts : fltparams, val : flt64 -> void) + pkglocal const flt32bfmt : (sb : strbuf#, opts : fltparams, val : flt32 -> void) ;; const Dblbias = 1023 const Fltbias = 127 -const flt64bfmt = {sb, val, mode, precision +const flt64bfmt = {sb, opts, val var isneg, exp, mant if isnan(val) @@ -41,10 +46,10 @@ const flt64bfmt = {sb, val, mode, precision ;; exp = max(exp, 1 - Dblbias) - dragon4(sb, isneg, mant, exp - 52, Dblbias, mode, precision) + dragon4(sb, isneg, mant, exp - 52, Dblbias, opts.mode, opts.prec) } -const flt32bfmt = {sb, val, mode, precision +const flt32bfmt = {sb, opts, val var isneg, exp, mant if isnan(val) @@ -64,7 +69,7 @@ const flt32bfmt = {sb, val, mode, precision ;; exp = (max((exp : int64), 1 - Fltbias) : int32) - dragon4(sb, isneg, (mant : uint64), (exp - 23 : int64), Fltbias, mode, precision) + dragon4(sb, isneg, (mant : uint64), (exp - 23 : int64), Fltbias, opts.mode, opts.prec) } /* diff --git a/lib/std/fmt.myr b/lib/std/fmt.myr index 60a94110..540d6d8e 100644 --- a/lib/std/fmt.myr +++ b/lib/std/fmt.myr @@ -315,10 +315,10 @@ const fallbackfmt = {sb, params, tyenc, ap : valist# -> void intfmt(sb, intparams(params), false, (val : uint64), 64) | `Tyflt32: var val : flt32 = vanext(ap) - flt32bfmt(sb, val, MNormal, 0) + flt32bfmt(sb, fltparams(params), val) | `Tyflt64: var val : flt64 = vanext(ap) - flt64bfmt(sb, val, MNormal, 0) + flt64bfmt(sb, fltparams(params), val) | `Tyvalist: sbputs(sb, "...") @@ -448,6 +448,27 @@ const fmtslice = {sb, subap, params ;; } +const fltparams = {params + var fp : fltparams + + fp = [ + .mode = MNormal, + .prec = 0, + ] + + for p : params + match p + | (opt, arg): + std.write(2, "fmt: ") + std.write(2, opt) + std.write(2, "arg: ") + std.write(2, arg) + std.die("\nunreachable\n") + ;; + ;; + -> fp +} + type intparams = struct base : size padto : size -- 2.23.0
[PATCH 0/5] Allow printing floating point in scientific notation | "S. Gilles" <sgilles@xxxxxxxxxxxx> |
- Prev by Date: [PATCH 0/5] Allow printing floating point in scientific notation
- Next by Date: [PATCH 2/5] Allow padding for fltXY formatting
- Previous by thread: [PATCH 0/5] Allow printing floating point in scientific notation
- Next by thread: [PATCH 2/5] Allow padding for fltXY formatting
- Index(es):