-
Notifications
You must be signed in to change notification settings - Fork 16
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
Default KINDs for constants and intrinsics #78
Comments
@FortranFan, thanks for this idea. I think this is a long standing issue in Fortran and a source of a lot of errors, at least in the codes that I have seen. Do you mind editing the title of this issue to just "Default KINDs for constants and intrinsics", the |
@certik wrote:
@certik , as asked, the title and the body have been edited - please let me know if there's anything else objectionable. |
@FortranFan thank you, I think it looks great! |
I have also made a request which is based on a similar concept that numbers declared with REAL(8) for example are exactly that. The issue is that if a number is not specified to be "doubnle precision" then at least one compilier will only assign 4-byte precision even though a number is declared 8 bytyes. So my request is that variables declared as REAL(8) (or other) are recognised as 8 byte precision and not left to a compiler preference. |
My understanding is that |
You are right, but my concern is that something like |
Yes, that is a common problem, and discussed in quite a few issues here and at Fortran discourse. If you read through the prior discussion, there are quite a few arguments why it might be difficult to fix this. So in order for any such proposal to succeed, you have to address the prior points. |
All bits are completely well defined, just not to what you think they should be. Come on. |
@klausler - What was the point of your comment? |
I think Peter's point was that the current standard defines exactly what happens and it has its logic and motivation and it is (relatively) consistent. I agree. But in my experience this is a point of confusion to almost every single new person to Fortran. I'll find the links to prior discussions later today. |
My point is that claiming that the lower order bits of the result of a 32-bit to 64-bit floating-point conversion are undefined random garbage is complete nonsense. If you don't like |
@klausler - Well, filling in with zeros to extend the data is one approach, but do you agree that the bits ought to have been extended to ensure that the number is consistent with the specified one when converted back from binary to decimal? |
@8bitmachine I think what @klausler meant is the representation of a number as sign, mantissa, and exponent bits in the floating-point representation as dictated by IEEE 754 standard. If you know the nuances of the mantissa bits, I think you should arrive at the conclusion that it is impossible to have a one-to-one mapping between binary and decimal for floating-point numbers. I suggest you grab a copy of the latest Fortran standard interpretation document J3/18-007r1 and look into the following:
|
Every binary number with a finite number of digits can be represented by a decimal number with a finite number of digits, but the converse is not true. |
I do know that decimal numbers and binary numbers do not have exact equvialents, of course. |
I would also add that it seems to me that selected_real_kind has not actually helped. |
There are already `real32` and `real64` kinds defined in `ISO_FORTRAN_ENV`,
isn't that enough?
…On Tue, May 24, 2022, 10:30 8bitmachine ***@***.***> wrote:
I would also add that it seems to me that selected_real_kind has not
actually helped.
Most computer systems these days implement the IEEE number formats in
full. Therefore, unlike earlier times, 32, 64 and extended precisions are
well established and should be the primary defaults. Fortran should in my
view recognise that.
If particular programs need greater resolution than offered by real(8) or
real(16) then perhaps the argument needs to be as to what the next
resolution standard should be. selected_real_kind does not really assure of
a particular resolution only a minimum which might be met.
Having to specify a real with a suffix seems to be as an imposition
similar to requiring the D descriptor.
No doubt Fortran community will tell me "selected_real_kind" is a step
forward. As a long time user of Fortran, I'm asking for a simpler option,
not a more complicated one.
—
Reply to this email directly, view it on GitHub
<#78 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMERY5DY47TZ3BQA4HFNPZDVLTRXLANCNFSM4JLXUJZA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
The problem here is that you're trying to change part of the language that is not context-sensitive into something that is. The type of a numeric literal (in Fortran and every other programming language that I know!) is self evident from the characters that constitute that literal. So you want to change that. Fine. What you need to do next is (1) figure out a way to not invalidate hundreds of millions of lines of existing code by changing the interpretation of their numeric literals and (2) figure out a way of defining, in a very precise and airtight way, how the context would affect the interpretation of numeric literals. Last, you may not like |
@wyphan |
There are at least two compilers I know of that, by default, use kind=1 for single precision and kind=2 for double precision. They are the NAG Fortran compiler and the Silverfrost FTN95 compiler. There may be others. But these are two I can know of off the top of my head. In both cases, compiler options can be used to change the defaults to byte-oriented kinds.
As previously mentioned, the real solution is use kind=real32 and kind=real64 from ISO_FORTRAN_ENV. For constants, you could write for example:
use iso_fortran_env
...
real(real64), parameter :: pi = 3.141592654_real64 ! Poor approximation
Or if you've been defining your own 'r4' and 'r8' kinds:
use iso_fortran_env
...
integer, parameter :: r4 = real32, r8 = real64
...
real(r8), parameter :: pi = 3.141592654_r8 ! Poor approximation
Which compiler are you using that doesn't support ISO_FORTRAN_ENV?
Walter
-----Original Message-----
From: j3-fortran/fortran_proposals
Sent: May 24, 2022 12:56 PM
To: j3-fortran/fortran_proposals
Cc: Subscribed
Subject: Re: [j3-fortran/fortran_proposals] Default KINDs for constants and intrinsics (#78)
@wyphan (https://github.com/wyphan)
Indeed, that sort of adds to my point that while selected_real_kind appears to offer a great flexibility in practice almost all, at least all the programs I have seen in industrial use, have used real(8) which I assume is the same as real64 ISO_FORTRAN_ENV which I would use if my compiler had it. I've never needed greater than that either, so real(4) and real(8) should have been sufficient. It also means I question the development of selected-real_kind if it was not going to offer guaranteed formats, as many of the possible real/exponent combinations won't be available or used. Must have seemed a good idea at the time.
@klausler (https://github.com/klausler), yes it may be that REAL(8) and REAL(4) would indeed set the context. I'm sure that is not beyond the capabilities of Fortran programmers. It is difficult to see, though, how extending a real(4) to a real(8) by zeroing the additional bits was a better solution as the context has changed for those variables defined as real(8). Presumably, like myself, programmers wishing to use 8 byte precision were expecting the context to change.
I guess I'll define real(r8) as a selected real kind (15,307) and have done with it. Does not alter my wish for a simpler system.
Therefore, if programmers are using some form of selected_real_kind definition a new term would only apply to
—
Reply to this email directly, view it on GitHub (#78 (comment)), or unsubscribe (https://github.com/notifications/unsubscribe-auth/ABCNQOY6TVWJ4RSC7XR26H3VLUX6HANCNFSM4JLXUJZA).
You are receiving this because you are subscribed to this thread.Message ID:
|
@8bitmachine , why not upvote the original post? It addresses the challenges thrown here by @klausler. Should there be any gaps or limitations or wrinkles with the proposal in the original post, the standard committee should and can step up to iron them out, if they can be influenced to again take up a solution to the situation. Note the proposal in the original post nearly had made its way into Fortran 2008 but was only deferred due to non-technical aspects. Consider the following program: double precision :: x = 0.1
print "(b0)", x
end Most processors based on the current standard will yield the following output:
Per your posts here and as mentioned by @certik re: many Fortranners, the above output is a bit (pun intended) confusing and can even lead to errors with unsuspecting users. With the proposal in the original post, the following modification will likely give many users the output they expect and also want with a possible conforming processor in the future: default real (kind=kind(1D0)) !<-- pseudo syntax
double precision :: x = 0.1
print "(b0)", x
end
|
A proposal from UK national body from year 2013: https://wg5-fortran.org/N1951-N2000/N1975.txt
The text was updated successfully, but these errors were encountered: