-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
printf and complex numbers #346
Comments
Good example of why we could use standard formatting functions that can be overloaded for different types of numbers. |
I guess the expected behavior here would be to print each component with the given format specifier? That seems reasonable enough, at least from the user interface perspective. I'll have to think about how best to do this. It implies that you want not only your formatting function as a whole to be a generic function, which can be specialized on different argument combinations, but also that you want each individual formatter to be generic as well so that it can have overloaded definitions. |
@JeffBezanson, is your idea that we just have a
Two concerns about this:
Another approach is to just say that the user has to deal with complex numbers. Writing this is not so bad:
|
An interesting generalization along similar lines would be doing things like this:
which would automatically iterate over the given arguments in tandem. However, this could be done at the level of writing additional methods for |
I think a slight level of indirection can accomplish what's requested here. The
It is specialized for the number of arguments, the specific generated functions
That is, for real values, it just applies the formatting function
This one method would enable all numeric format specifiers to print complex numbers. |
Unfortunately in that scenario I can no longer guarantee that the |
Yeah, I think that's fair. While very generic, this is an overly complicated approach for something that can be handled more flexibly on the user side. |
It just seems inelegant for complex number printing to be handled in user code. |
Easiest would probably be to have a format character for it, but I'm not sure there are any letters left! :) |
What if we use the same one for reals, but print complex numbers when those are passed in - %f ? -viral On Jan 19, 2012, at 10:30 AM, JeffBezanson wrote:
|
Then what about Rational? |
Can't %f be a stand-in for all kinds of numbers passed in? It really just says that interpret the input as floating point with number of digits to print. Alternatively, for rational, we may just use %d. -viral On Jan 19, 2012, at 11:05 AM, JeffBezanson wrote:
|
Personally, I suspect printf just has too many features, making it harder than necessary to figure out how to factor the functionality. |
Having struggled with implementing and then reimplementing it better for well over a week now, I can attest to this being true. I don't think we should add to the problem. I don't see where the benefit from being able to print complex values using |
For example, our printf can do these tricks:
|
Closing this since the discussion clearly shows that we'd rather not add more functionality to printf. |
Backport bswap method for complex numbers.
To allow rendering the track's documents on the v3 website, we're introducing a docs/config.json file. This commit adds the docs/config.json file.
How do we handle complex numbers in printf? It would be nice to handle them. Does C99 say anything on the topic?
The text was updated successfully, but these errors were encountered: