-
Notifications
You must be signed in to change notification settings - Fork 178
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
Routines to convert real/complex values to character values #337
Comments
A few points for discussion:
|
IMO, |
Would it be an optional argument, As an example in fortran-utils @certik had the following:
Should the user formatting re-use the Fortran formatting conventions or do we want to adopt something like the Format Specification Mini-Language in Python? Personally I would be in favor of having a function called |
A Formatting reals is more complicated than just the decimal places. First, there are plenty of formatters for reals available: print'(f10.4)', 42.27e-3
print'(d10.4)', 42.27e-3
print'(g10.4e1)', 42.27e-3
print'(e10.4e1)', 42.27e-3
print'(es10.4e1)', 42.27e-3
end
I usually prefer to use For the default conversion, I would strongly prefer that the round-trip real -> character -> real works as lossless as possible. |
I don't have a preference as long as there is a unique name (e.g. |
We might be able to port something like flang's self-contained |
https://urbanjost.github.io/M_msg/man3.html |
The general issue to solve with this is the conversion from intrinsic data types to character values, which is in Fortran only possible by internal IO:
This is error prone since the character variable has to be a fixed size character variable with sufficient length and this approach is not usable in a functional way. In #69 such functionality for stdlib has been briefly discussed. This issue should work out the details for such routines.
Converting integers and logicals to character values without internal IO is quite straight-forward (see #336), somewhat less straight-forward is reliably converting real and complex values to character sequences.
To get started such routines for the real and complex case could be implemented by internal IO until we found a robust way to handle all exceptional values (
NaN
,Inf
,-Inf
) and correctly write the decimal places and exponent for a given real or complex value without resorting to internal IO or excessive use of logarithms and exponentials.The text was updated successfully, but these errors were encountered: