-
Notifications
You must be signed in to change notification settings - Fork 187
Function in stdlib
to get NaN
#147
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
Comments
stdlib
to get NaN
and internally implement it by any of the approaches that were discussed (ieee_value
, sqrt
or huge
). That way we have just one simple place to modify, and the rest of stdlib uses get_nan
stdlib
to get NaN
I agree with the proposition, and would like to make it available such a function rather soon, even if the implementation will change later. I do not want to "hack" the discussion but I would suggest to have an unified discussion for the three quantities: Since, they will be "special" values I would prefer an standard way to handling them rather than having each routine developer handling it individually. |
I agree.
Good point. There are already some comments about infinity in #118 . |
First, let me clarify that I suggested I want to emphasize that the standard is written in a way that does not assume the existence of NaN and positive/negative infinity except for IEEE real kinds. That means the So there is a fundamental friction between practical concerns (we want to be able to produce and test for NaN) and a basic concept of the language ( With that in mind, I propose that we have a pre-processor test for whether the Of the fallback approaches discussed so far, I like the internal |
Let's brainstorm the name of this function. The internal implementation of it can be decided upon later, and also changed easily. Here are some possible names that come to my mind:
Using the naming convention of "two syllables do not need a _", the So I vote for Update: based on the discussion below, I now think |
Assuming we want to be able to produce NaNs of various kinds, I suggest the following API pure elemental function nan_<kind>(x)
real(<kind>), intent(in) :: x
real(<kind>) :: nan_<kind>
end function nan_<kind> where the different This approach is modeled on the intrinsic I think there is no question about the API for pure elemental function isnan_<kind>(x)
real(<kind>), intent(in) :: x
logical :: isnan_<kind>
end function isnan_<kind> The only challenge is having to be careful about playing nicely with the pre-existing (non-standard) |
It sounds good to me. It is a similar API to
Based on @nshaffer reason, I vote for
As fas as I know, when implemented, |
Yes, |
I'm fine with either If we do choose to go with pure elemental function nan_default()
real(real32) :: nan_default
end function nan_default which would be also overloaded by the generic Nevertheless, for people like me who almost exclusively work with single precision, |
I am also fine with |
It sounds like we have a consensus on the name and API. Based on this thread: nanDescription
Syntax
Argument
Return valueIf IEEE is supported, the result is IEEE NaN and of the same type as To progress a bit on this function:
The choice could be made at the compilation through CMake (and for |
What module does |
I don't see an issue with allowing I don't think the standard has any qualms with functions without arguments, see As for which module to put this in, I think |
I see your point and agree with you for this function.
Both are fine for me, with a preference for |
So this is an irrelevant detail, but I thought I'd share my findings: if I think we are not holding stdlib functions and subroutines to the same level of rigor as intrinsic ones, so the point is moot, but that's the answer. |
Question: Which compilers do not support IEEE |
Is this being worked on? |
I would suggest we provide a function
get_nan
and internally implement it by any of the approaches that were discussed (ieee_value
,sqrt
orhuge
). That way we have just one simple place to modify, and the rest of stdlib usesget_nan
and thus does not have to be modified. We should discuss a good name for such a function.Originally posted by @certik in #128 (comment)
There was some discussion in #128 about
NaN
and how to generate it (not all compilers supportieee_arithmetic
and its functionieee_value
. Therefore, if could be nice to have such a function instdlib
that would work for all compilers.In #128, the following solutions were proposed:
ieee_value
(fromieee_arithmetic.f90
)sqrt
of a negative number (as implemented in gccieee_arithmetic.f90
)huge
(which does not returnNaN
??) @nshafferInternal I/O to generate
NaN
(@urbanjost )transfer
method (@leonfolks )Possible name for this function:
get_nan
Hopefully I didn't miss a proposition.
The text was updated successfully, but these errors were encountered: