mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 11:08:20 +00:00
Fix to_json() to not lose precision for values of type double
Also changed a few values in the tests for better numerical diversity.
This commit is contained in:
parent
65d6e5a4f7
commit
6812a7febe
3 changed files with 11 additions and 10 deletions
|
@ -39,10 +39,11 @@ function to_json(v: any, only_loggable: bool &default=F, field_escape_pattern: p
|
|||
case "count":
|
||||
fallthrough;
|
||||
case "time":
|
||||
fallthrough;
|
||||
case "double":
|
||||
return cat(v);
|
||||
|
||||
case "double":
|
||||
return fmt("%.16g", v);
|
||||
|
||||
case "bool":
|
||||
local bval: bool = v;
|
||||
return bval ? "true" : "false";
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
true
|
||||
123
|
||||
-999
|
||||
1.123457
|
||||
-1.123456e+308
|
||||
0
|
||||
1.0
|
||||
3.14
|
||||
-1.23456789e+308
|
||||
9e-308
|
||||
1480788576.868945
|
||||
"-12.0 hrs"
|
||||
"hello"
|
||||
""
|
||||
|
|
|
@ -30,14 +30,14 @@ event bro_init()
|
|||
local i: int = -999;
|
||||
print to_json(i);
|
||||
|
||||
local d1: double = 1.123456789;
|
||||
local d2: double = -1.123456e308;
|
||||
local d3: double = 9.876543e-308;
|
||||
local d1: double = 3.14;
|
||||
local d2: double = -1.23456789e308;
|
||||
local d3: double = 9e-308;
|
||||
print to_json(d1);
|
||||
print to_json(d2);
|
||||
print to_json(d3);
|
||||
|
||||
local t: time = double_to_time(1.0);
|
||||
local t: time = double_to_time(1480788576.868945);
|
||||
print to_json(t);
|
||||
|
||||
local ti: interval = -12hr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue