Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue when IEEE floating-point rounding mode is IEEE_DOWN #545

Merged
merged 1 commit into from
May 19, 2024

Conversation

amanotk
Copy link
Contributor

@amanotk amanotk commented Nov 9, 2023

This solves an issue when IEEE floating-point rounding mode is manually set to IEEE_DOWN.
The original code in the string_to_integer subroutine

        ndigits_digits = floor(log10(real(ndigits)))+1

erroneously returns 1 even when ndigits is 10 (while the correct value should be 2).

The following code is the minimum reproducible example of the problem.
The last deserialize will result in a crush.

program jsontest
  use :: ieee_arithmetic
  use :: json_module

  type(json_file) :: file

  call ieee_set_rounding_mode(ieee_down) 

  call file%initialize()

  call file%deserialize('{"foo" : 100}')
  print *, "ok 1"
  call file%deserialize('{"foo" : 100, "bar" : 1000}')
  print *, "ok 2"
  call file%deserialize('{"foo" : 100, "bar" : 1000, "baz" : 10000}')
  print *, "ok 3"

  call file%destroy()

end program jsontest

I assume simply changing floor to nint should solve the issue without any side effects.

amanotk added a commit to WumingCode/WumingPIC2D that referenced this pull request Nov 9, 2023
@jacobwilliams
Copy link
Owner

thanks! I'll take a look at this...

Copy link

codecov bot commented Nov 18, 2023

Codecov Report

Merging #545 (e4bfffc) into master (7819919) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #545   +/-   ##
=======================================
  Coverage   89.48%   89.48%           
=======================================
  Files           7        7           
  Lines        5356     5356           
=======================================
  Hits         4793     4793           
  Misses        563      563           

@jacobwilliams jacobwilliams merged commit fff5372 into jacobwilliams:master May 19, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants