diff --git a/lib/poison/parser.ex b/lib/poison/parser.ex index cad8ba6..261ccae 100644 --- a/lib/poison/parser.ex +++ b/lib/poison/parser.ex @@ -394,6 +394,10 @@ defmodule Poison.Parser do @compile {:inline, number_complete: 5} + defp number_complete(_decimal, skip, sign, coef, 0) do + [coef * sign | skip] + end + if Code.ensure_loaded?(Decimal) do defp number_complete(true, skip, sign, coef, exp) do [%Decimal{sign: sign, coef: coef, exp: exp} | skip] @@ -404,10 +408,6 @@ defmodule Poison.Parser do end end - defp number_complete(_decimal, skip, sign, coef, 0) do - [coef * sign | skip] - end - max_sig = 1 <<< 53 # See: https://arxiv.org/pdf/2101.11408.pdf diff --git a/test/poison/parser_test.exs b/test/poison/parser_test.exs index 6acba41..961f816 100644 --- a/test/poison/parser_test.exs +++ b/test/poison/parser_test.exs @@ -54,10 +54,11 @@ defmodule Poison.ParserTest do # credo:disable-for-next-line Credo.Check.Readability.LargeNumbers assert parse!("123456789.123456789e123") === 1.234567891234568e131 - assert parse!("0", %{decimal: true}) == Decimal.new("0") - assert parse!("-0", %{decimal: true}) == Decimal.new("-0") - assert parse!("99", %{decimal: true}) == Decimal.new("99") - assert parse!("-99", %{decimal: true}) == Decimal.new("-99") + assert parse!("0", %{decimal: true}) == 0 + assert parse!("-0", %{decimal: true}) == -0 + assert parse!("99", %{decimal: true}) == 99 + assert parse!("-99", %{decimal: true}) == -99 + assert parse!("99.99", %{decimal: true}) == Decimal.new("99.99") assert parse!("-99.99", %{decimal: true}) == Decimal.new("-99.99") assert parse!("99.99e99", %{decimal: true}) == Decimal.new("99.99e99")