From 496aba7fbcc1ce341fbcc0cf28d9ff36a28bce78 Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 11 Nov 2021 16:21:01 +1300 Subject: [PATCH] [FileFormats.NL] Fix printing of large integers --- src/FileFormats/NL/NL.jl | 7 ++++++- test/FileFormats/NL/NL.jl | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/FileFormats/NL/NL.jl b/src/FileFormats/NL/NL.jl index d361e3f75d..5c957be11b 100644 --- a/src/FileFormats/NL/NL.jl +++ b/src/FileFormats/NL/NL.jl @@ -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) diff --git a/test/FileFormats/NL/NL.jl b/test/FileFormats/NL/NL.jl index 24b37e1ea2..c20a25571b 100644 --- a/test/FileFormats/NL/NL.jl +++ b/test/FileFormats/NL/NL.jl @@ -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_")