[J3] [BULK] Re: Upcoming gfortran 15 will contain an implementation of unsigned numbers
Malcolm Cohen
malcolm at nag-j.co.jp
Tue Oct 15 23:30:13 UTC 2024
Well, I beg to differ on the " manual detection of overflow would be impossible if" assertion. That is not the case. The detection code is different, that's all.
But manual detection is not the issue, as one would hardly decorate every addition with manual detection code. One would hope the compiler would support doing that automatically, as a debugging aid. The compiler cannot do that if it is not allowed to, though.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
-----Original Message-----
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Thomas Konig via J3
Sent: Wednesday, October 16, 2024 3:22 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Thomas König <tk at tkoenig.net>
Subject: Re: [J3] [BULK] Re: Upcoming gfortran 15 will contain an implementation of unsigned numbers
Am 15.10.24 um 17:36 schrieb Johnson, Ted via J3:
> I believe the answer is "an undetectable wrap modulo 2**N, as in C" -
Yes, it is modulo 2^n, like C.
I beg to differ on the "undetectable" part; but this requires manual code, just like in C.
An example, which compiles with current gfortran -funsigned :
subroutine add_with_overflow (a, b, c, overflow)
use iso_fortran_env, only: uint64
unsigned(uint64), intent(in) :: a, b
unsigned(uint64), intent(out) :: c
logical, intent(out) :: overflow
c = a + b
overflow = c < a
end subroutine add_with_overflow
A side note, manual detection of overflow would be impossible if overflowing a + b would be prohibited.
Best regards
Thomas
More information about the J3
mailing list