-
Notifications
You must be signed in to change notification settings - Fork 757
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
sclang: print floats with at least 1 decimal place #3585
Conversation
Awesome, thanks! |
Ah good. will We'll be able to get rid of the code of storeOn { |stream|
var str;
if(this == inf) { stream << "inf"; ^this };
if(this == -inf) { stream << "-inf"; ^this };
str = super.asString;
stream << str;
// if it doesn't already have a . or is 1e-05 then add a .0 to force it to Float
if(str.find(".").isNil and: { str.find("e").isNil }) {
stream << ".0";
}
} actually, I just found a bug here: (0/0).asCompileString // returns nan.0 |
Fixes #3573 Floats that are equal to an integer are printed with .0
@telephon - good catch! I've patched it and added tests, they pass locally. Do you think it's ok for me to just remove Float.storeOn entirely and let it call SimpleNumber's? It appears that the current implementation has a similar bug anyway: c = CollStream.new;
(0/0).storeOn(c);
c.contents; // "nan.0" |
Also, I noticed this comment - supercollider/SCClassLibrary/Common/Math/Float.sc Lines 67 to 69 in cca12ff
Should I use this same method for |
The question is whether we want the If we take the two to be the same, I tend to recommend first to fix the |
I don't understand the difference between these two; I've never used them directly, and I can't find any documentation that explains it at any level of detail. It seems like |
I didn't realize that these two methods are undocumented. I'll try a short explanation. Note that many implementations of these two methods could be still improved. printOn (asString)produce a string that represents the object close enough for a human reader. By default, this only returns the class name (e.g. The REPL calls SinOsc.ar // -> "a SinOsc"
(freq: 600, amp: 0.1) // -> "( 'freq': 600, 'amp': 0.1 )"
Event.default // -> "( )"
List[1, 2, 3] // -> "List[ 1, 2, 3 ]"
a = [1, 2, 3].add(a); -> "[ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2, 3, [ 1, 2...etc..."
storeOn (asCompileString)produce a string that, when evaluated, returns an object equal to the object. For example the above This can be a way to store objects in a human readable form. Not all objects can be reproduced this way, and for some objects the representation is not possible or otherwise problematic. Then the method |
Maybe yes. It would of course be ideal if, for |
Thanks again for all your great work on this one folks! :-) |
You're welcome!
Could we do this in a separate PR @telephon ? This one is all ready to go as-is and I'm still not sure I understand what you want re: storeOn/printOn. |
@brianlheim sure! |
I guess it's a bit of a side note, but this change accidentally broke Ambisonics Toolkit. ATK looks up impulse responses based in part on the server's sample rate. The server reports the sample rate back to the client as a float. Then ATK does So what used to be a path On the one hand, this change is technically sound. I'm not suggesting to revert. On the other, something is wrong with our process if we all thought that string representations are purely cosmetic, and we all forgot that strings may refer to disk locations that are not flexible, and some parts of the path might be numeric. It bothers me that not a single one of us (myself, too) considered it at all. |
yeah, it's definitely kinda troubling. i've documented it as a breaking change in the 3.10 changelog, so it will at least be very visible in the release notes. |
dang. for the record, seems like we broke another thing: https://www.listarc.bham.ac.uk/lists/sc-users/msg62217.html like i said in the thread, if your code breaks because of this change, it's probably relying on pretty fragile logic anyway. but either way, we have some lessons to take away from this. no one in particular is at fault, but we all majorly underestimated the impact of this PR. |
Fixes #3573
Floats that are equal to an integer are printed with .0
I couldn't find a way to do this without actually scanning the string to
see if '.0' needs to be appended. "%.9f" will print extra significant
digits; and "%#.14g" will do the same. I think possibly switching on
the point where numbers change to scientific notation (1e14) and then
using "%#.14f" would work, but I'm not sure if that's a portable
solution and this seems a bit cleaner.
Before:
After: