oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1package svg
2
3import (
4 "math"
5 "testing"
6)
7
8// TestNumNeverWritesNegativeZero: a coordinate that is zero is "0",
9// whatever its sign. On arm64 the fitting arithmetic can fuse a
10// multiply and add into -0 (and a tiny negative rounds to it), and
11// "-0" is not what a number in these attributes is written as.
12func TestNumNeverWritesNegativeZero(t *testing.T) {
13 for _, v := range []float64{math.Copysign(0, -1), -0.00001, -0.00004999, 0, 0.00001} {
14 if got := num(v); got != "0" {
15 t.Errorf("num(%v) = %q, want 0", v, got)
16 }
17 }
18 for v, want := range map[float64]string{-1.5: "-1.5", 126.72000000000001: "126.72", -0.0001: "-0.0001", 1707.008: "1707.008"} {
19 if got := num(v); got != want {
20 t.Errorf("num(%v) = %q, want %q", v, got, want)
21 }
22 }
23}
24