Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/FileFormats/NL/NL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,12 @@ function _process_constraint(
return
end

_str(x::Float64) = isinteger(x) ? string(round(Int, x)) : string(x)
function _str(x::Float64)
if isinteger(x) && (typemin(Int) <= x <= typemax(Int))
return string(round(Int, x))
end
return string(x)
end

_write_term(io, x::Float64, ::Any) = println(io, "n", _str(x))
_write_term(io, x::Int, ::Any) = println(io, "o", x)
Expand Down
8 changes: 8 additions & 0 deletions test/FileFormats/NL/NL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,14 @@ function test_moi()
return
end

function test_float_rounding()
@test NL._str(1.0) == "1"
@test NL._str(1.2) == "1.2"
@test NL._str(1e50) == "1.0e50"
@test NL._str(-1e50) == "-1.0e50"
return
end

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$(name)", "test_")
Expand Down