main 98594d0

jsnumber_test.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package expr
4
5import (
6	"math"
7	"strconv"
8	"strings"
9)
10
11// The helpers below reproduce what the JavaScript reference prints for a
12// number. The package itself follows the C# runner (numberToCoercedString);
13// the oracle tests need the JavaScript form to read the recorded tokens.
14
15// jsNumberToString is Number.prototype.toString: the shortest decimal that
16// round-trips, in positional notation for exponents from -7 to 20 and in
17// exponent notation ("1e+21", "1.5e-7") beyond.
18func jsNumberToString(x float64) string {
19	switch {
20	case math.IsNaN(x):
21		return "NaN"
22	case x == 0:
23		return "0"
24	case math.IsInf(x, 1):
25		return "Infinity"
26	case math.IsInf(x, -1):
27		return "-Infinity"
28	}
29	sign := ""
30	if x < 0 {
31		sign = "-"
32		x = -x
33	}
34	s := strconv.FormatFloat(x, 'e', -1, 64) // d.ddde±xx
35	mant, expStr, _ := strings.Cut(s, "e")
36	exp, _ := strconv.Atoi(expStr)
37	digits := strings.Replace(mant, ".", "", 1)
38	k := len(digits)
39	n := exp + 1
40	switch {
41	case k <= n && n <= 21:
42		return sign + digits + strings.Repeat("0", n-k)
43	case 0 < n && n <= 21:
44		return sign + digits[:n] + "." + digits[n:]
45	case -6 < n && n <= 0:
46		return sign + "0." + strings.Repeat("0", -n) + digits
47	}
48	e := n - 1
49	esign := "+"
50	if e < 0 {
51		esign = "-"
52		e = -e
53	}
54	if k == 1 {
55		return sign + digits + "e" + esign + strconv.Itoa(e)
56	}
57	return sign + digits[:1] + "." + digits[1:] + "e" + esign + strconv.Itoa(e)
58}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 3

↑↓ moveenter openesc close