summaryrefslogtreecommitdiff
path: root/lib/std/fmt.myr
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2019-09-09 07:53:57 -0400
committerS. Gilles <sgilles@math.umd.edu>2019-09-09 10:24:24 -0400
commit82eecd5a321aa3c619437a21997aa73c33c31d3c (patch)
tree4b22de296e6d0ec849d8f8d64fecf7a732f9a282 /lib/std/fmt.myr
parentb5ddbc86346fddc60360a817ee62bc8ca938973e (diff)
downloadmc-82eecd5a321aa3c619437a21997aa73c33c31d3c.tar.gz
Split out intfmt to a separate file.
This prepares for intfmt being used within fltfmt for the exponent in scientific notation.
Diffstat (limited to 'lib/std/fmt.myr')
-rw-r--r--lib/std/fmt.myr61
1 files changed, 1 insertions, 60 deletions
diff --git a/lib/std/fmt.myr b/lib/std/fmt.myr
index 5dc3ba3..b981a74 100644
--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -7,6 +7,7 @@ use "fltfmt"
use "hashfuncs"
use "hasprefix"
use "htab"
+use "intfmt"
use "intparse"
use "introspect"
use "memops"
@@ -477,12 +478,6 @@ const fltparams = {params
-> fp
}
-type intparams = struct
- base : size
- padto : size
- padfill : char
-;;
-
const intparams = {params
var ip : intparams
@@ -572,60 +567,6 @@ const isprint = {b
-> b >= (' ' : byte) && b < ('~' : byte)
}
-const digitchars = "0123456789abcdef"
-const intfmt = {sb, opts, signed, bits : uint64, nbits
- var isneg
- var sval, val
- var b : byte[64]
- var i, j, npad
- var base
-
- base = (opts.base : uint64)
- if signed && bits >= 1 << (nbits - 1)
- sval = -(bits : int64)
- val = (sval : uint64)
- isneg = true
-
- /* if its negative after inverting, we have int64 min */
- if sval < 0
- std.sbputs(sb, "-9223372036854775808")
- -> void
- ;;
- else
- val = (bits : uint64)
- val &= ~0 >> nbits
- isneg = false
- ;;
-
- i = 0
- if val == 0
- b[0] = ('0' : byte)
- i++
- ;;
- while val != 0
- b[i] = digitchars[val % base]
- val /= base
- i++
- ;;
-
- npad = clamp(opts.padto - i, 0, opts.padto)
- if isneg
- npad--
- ;;
- if opts.padfill == '0' && isneg
- sbputb(sb, ('-' : byte))
- ;;
- for j = 0; j < npad; j++
- sbputc(sb, opts.padfill)
- ;;
- if opts.padfill != '0' && isneg
- sbputb(sb, ('-' : byte))
- ;;
- for j = i; j != 0; j--
- sbputb(sb, b[j - 1])
- ;;
-}
-
/* would use std.get(), but that's a dependency loop */
const getint = {s, msg
match std.intparse(s)