mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-28 17:01:02 +02:00
Add std.sign and fix division by zero in stdlib
This commit is contained in:
parent
bed2cd89bc
commit
44770e75dd
16835
ast/stdast.go
16835
ast/stdast.go
File diff suppressed because it is too large
Load Diff
@ -481,7 +481,7 @@ limitations under the License.
|
|||||||
local whole = std.floor(n_);
|
local whole = std.floor(n_);
|
||||||
local dot_size = if prec == 0 && !ensure_pt then 0 else 1;
|
local dot_size = if prec == 0 && !ensure_pt then 0 else 1;
|
||||||
local zp = zero_pad - prec - dot_size;
|
local zp = zero_pad - prec - dot_size;
|
||||||
local str = render_int(n__ / n_ * whole, zp, 0, blank, sign, 10, "");
|
local str = render_int(std.sign(n__) * whole, zp, 0, blank, sign, 10, "");
|
||||||
if prec == 0 then
|
if prec == 0 then
|
||||||
str + if ensure_pt then "." else ""
|
str + if ensure_pt then "." else ""
|
||||||
else
|
else
|
||||||
@ -711,6 +711,16 @@ limitations under the License.
|
|||||||
else
|
else
|
||||||
if n > 0 then n else -n,
|
if n > 0 then n else -n,
|
||||||
|
|
||||||
|
sign(n)::
|
||||||
|
if std.type(n) != "number" then
|
||||||
|
error "std.sign expected number, got " + std.type(n)
|
||||||
|
else
|
||||||
|
if n > 0 then
|
||||||
|
1
|
||||||
|
else if n < 0 then
|
||||||
|
-1
|
||||||
|
else 0,
|
||||||
|
|
||||||
max(a, b)::
|
max(a, b)::
|
||||||
if std.type(a) != "number" then
|
if std.type(a) != "number" then
|
||||||
error "std.max first param expected number, got " + std.type(a)
|
error "std.max first param expected number, got " + std.type(a)
|
||||||
|
6
testdata/object_invariant7.golden
vendored
6
testdata/object_invariant7.golden
vendored
@ -5,7 +5,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
|
|||||||
{ x: 5, assert super.x == 5 }
|
{ x: 5, assert super.x == 5 }
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:1036:29-30 thunk from <thunk <ta> from <function <anonymous>>>
|
<std>:1046:29-30 thunk from <thunk <ta> from <function <anonymous>>>
|
||||||
|
|
||||||
local ta = std.type(a);
|
local ta = std.type(a);
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
|
|||||||
<builtin> builtin function <type>
|
<builtin> builtin function <type>
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:1038:33-35 thunk from <function <anonymous>>
|
<std>:1048:33-35 thunk from <function <anonymous>>
|
||||||
|
|
||||||
if !std.primitiveEquals(ta, tb) then
|
if !std.primitiveEquals(ta, tb) then
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
|
|||||||
<builtin> builtin function <primitiveEquals>
|
<builtin> builtin function <primitiveEquals>
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:1038:12-40 function <anonymous>
|
<std>:1048:12-40 function <anonymous>
|
||||||
|
|
||||||
if !std.primitiveEquals(ta, tb) then
|
if !std.primitiveEquals(ta, tb) then
|
||||||
|
|
||||||
|
1
testdata/percent_format_float.golden
vendored
Normal file
1
testdata/percent_format_float.golden
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
"0.000000"
|
1
testdata/percent_format_float.jsonnet
vendored
Normal file
1
testdata/percent_format_float.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
"%f" % 0
|
Loading…
x
Reference in New Issue
Block a user