File: print.go

package info (click to toggle)
golang-github-sanity-io-litter 1.1.0%2Bgit20171129.f8fd6a5-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 152 kB
  • sloc: makefile: 2
file content (44 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package litter

import (
	"io"
	"strconv"
)

func printBool(w io.Writer, value bool) {
	if value {
		w.Write([]byte("true"))
		return
	}
	w.Write([]byte("false"))
}

func printInt(w io.Writer, val int64, base int) {
	w.Write([]byte(strconv.FormatInt(val, base)))
}

func printUint(w io.Writer, val uint64, base int) {
	w.Write([]byte(strconv.FormatUint(val, base)))
}

func printFloat(w io.Writer, val float64, precision int) {
	w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision)))
}

func printComplex(w io.Writer, c complex128, floatPrecision int) {
	w.Write([]byte("complex"))
	printInt(w, int64(floatPrecision*2), 10)
	r := real(c)
	w.Write([]byte("("))
	w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision)))
	i := imag(c)
	if i >= 0 {
		w.Write([]byte("+"))
	}
	w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision)))
	w.Write([]byte("i)"))
}

func printNil(w io.Writer) {
	w.Write([]byte("nil"))
}