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

Throw error for if result of NINT overflows its kind #4079

Closed
HarshitaKalani opened this issue May 24, 2024 · 3 comments · Fixed by #4133
Closed

Throw error for if result of NINT overflows its kind #4079

HarshitaKalani opened this issue May 24, 2024 · 3 comments · Fixed by #4133
Labels
intrinsic Issue or pull request specific to intrinsic function

Comments

@HarshitaKalani
Copy link
Contributor

program main
    print*, nint(1e12_8)
    print*, nint(1000000000000.0000000000000000d0)
end
$ gfortran b.f90 && ./a.out
b.f90:2:17:

    2 |     print*, nint(1e12_8)
      |                 1
Error: Result of IDNINT overflows its kind at (1)
b.f90:3:17:

    3 |     print*, nint(1000000000000.0000000000000000d0)
      |                 1
Error: Result of IDNINT overflows its kind at (1)
$ lfortran b.f90
-727379968
-727379968
@HarshitaKalani HarshitaKalani added the intrinsic Issue or pull request specific to intrinsic function label May 24, 2024
@HarshitaKalani
Copy link
Contributor Author

The following should work.

program main
    print*, nint(1e12_8, 8)
    print*, nint(1000000000000.0000000000000000d0, 8)
end
$ gfortran b.f90 && ./a.out
        1000000000000
        1000000000000
$ lfortran b.f90
1000000000000
1000000000000

@shivimathur
Copy link
Contributor

@HarshitaKalani, in the first test, aren't the kinds of both, 1e12_8 and 1000000000000.0000000000000000d0 equal to 8? If it is so, why is gfortran producing an error whereas it gives an answer in the second test?

@HarshitaKalani
Copy link
Contributor Author

When we do not provide kind value in nint, it returns the result converted to an INTEGER of the default kind which is 4. So the output for test 1 will have kind = 4 and that's why the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
intrinsic Issue or pull request specific to intrinsic function
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants