瀏覽代碼

Change errors for bignums to be more explicit

Co-Authored-By: Stephan Renatus <srenatus@chef.io>
pull/184/head
Paul J. Davis 6 年之前
父節點
當前提交
496d7f0ccd
共有 2 個檔案被更改,包括 14 行新增2 行删除
  1. +12
    -2
      src/jiffy.erl
  2. +2
    -0
      test/jiffy_03_number_tests.erl

+ 12
- 2
src/jiffy.erl 查看文件

@ -119,9 +119,19 @@ finish_decode({bignum_e, Value}) ->
{E, []} = string:to_integer(ExpStr),
{I, E}
end,
IVal * math:pow(10, EVal);
try
IVal * math:pow(10, EVal)
catch
error:badarith ->
error({range, EVal})
end;
finish_decode({bigdbl, Value}) ->
list_to_float(binary_to_list(Value));
try
list_to_float(binary_to_list(Value))
catch
error:badarg ->
error({range, Value})
end;
finish_decode({Pairs}) when is_list(Pairs) ->
finish_decode_obj(Pairs, []);
finish_decode(Vals) when is_list(Vals) ->

+ 2
- 0
test/jiffy_03_number_tests.erl 查看文件

@ -98,6 +98,8 @@ cases(error) ->
<<"1E">>,
<<"1-E2">>,
<<"2E +3">>,
<<"1E3000">>,
<<"0.1E30000">>,
<<"1EA">>
];

Loading…
取消
儲存