@@ -7,7 +7,6 @@ using Observables: @map
77export showtable
88
99const ag_grid_imports = []
10- const js_max_safe_int = Int128 (2 ^ 53 - 1 )
1110
1211function __init__ ()
1312 version = readchomp (joinpath (@__DIR__ , " .." , " ag-grid.version" ))
@@ -259,6 +258,14 @@ function _showtable_async!(w, schema, names, types, rows, coldefs, tablelength,
259258 onimport (w, handler)
260259end
261260
261+ function _is_javascript_safe (x:: Integer )
262+ - Int128 (2 ^ 53 )- 1 < x < Int128 (2 ^ 53 )- 1
263+ end
264+
265+ function _is_javascript_safe (x:: AbstractFloat )
266+ - 2 ^ 53 - 1 < x < 2 ^ 53 - 1
267+ end
268+
262269# directly write JSON instead of allocating temporary dicts etc
263270function table2json (schema, rows, types; requested = nothing )
264271 io = IOBuffer ()
@@ -273,7 +280,7 @@ function table2json(schema, rows, types; requested = nothing)
273280 columnwriter = JSON. Writer. CompactContext (io)
274281 JSON. begin_object (columnwriter)
275282 Tables. eachcolumn (schema, row) do val, ind, name
276- if val isa Real && isfinite (val) && - js_max_safe_int < trunc (Int128, val) < js_max_safe_int
283+ if val isa Real && isfinite (val) && _is_javascript_safe ( val)
277284 JSON. show_pair (columnwriter, ser, name, val)
278285 elseif val === nothing || val === missing
279286 JSON. show_pair (columnwriter, ser, name, repr (val))
0 commit comments