-
Notifications
You must be signed in to change notification settings - Fork 57
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
improvements to float32 support needed #172
Comments
I saw casting was mentioned for integers using Math.Trunc (however, this function seem to have been renamed Truncate now) It feels a bit weird that it currently maps to js/ts trunc which is more like floor in the way that it supports values outside the integer range, I feel it would be more consistent to map it to (x) => x|0 Anyway, glad to find this cool project! |
Thank you for kind words! There are no There are no number cast operators. If you want a number of a different type, assign it to a new variable. The result of |
I see, I was thinking about cases like audio and graphics (using float for better performance)
Sorry, yes, I realize now it is only relevant for the 32-bit case. |
Indeed, for heavy calculations, I intended the double d = Math.Sin(doubleAngle);
float f = Math.Sin(floatAngle); The above are unambiguous and it's possible to transpile the second one to double x = Math.Sin(floatAngle); // Math.Sin or MathF.Sin?
float y = 5 * Math.Sin(floatAngle); // float multiplication or double multiplication? Now I think that adopting .NET's explicit
Not sure what you're referring to, but Python has bignums:
|
Nice, being explicit is probably the best way, will be easier to reason about the code.
wow, that's sweet! I knew it had bignums, I never realized it's THE native int type! |
I keep thinking of the API design. I expect the calculations to consistently use double x = Math.Sin(floatAngle); // MathF.Sin
float y = 5 * Math.Sin(floatAngle); // float multiplication In rare cases where precision needs to be mixed, intermediate variables can be introduced. I'm going to fully read the MathF story, but at first it looks the reasons were backward compatibility ( .NET 7 adds |
I agree that we can assume mixed precision is not a common/important case MathF is a pretty ugly prefix, Unity game engine has its own Mathf as well, so there is already at least 3 in Unity...
hmm, never saw that, but quite nice, possibly the best so far?
hmm, this would take some time to get use to, sin with empty parens, weird... My personal preference is like C-style global sin(), but accepting multiple types like hlsl/glsl. |
I decided to add Being explicit about the type is not how computations generally work in high-level languages. We are used to overloaded arithmetic operators. I see no reason to spell Not closing this ticket yet, as tests need to be added and |
I agree it's much more elegant if this can be solved using overloading! Let me explain more about the context why I would like to see float literals supported... So the use case here is not really high level, nor a complete app, I would run fusion to emit js during prototyping, and then export a high performant C.
so yeah, a very extreme example, and a very fringe use case in the grand scheme of things... So you might be better off ignoring this unless these are easy fixes... An alternative approach that would work for this use case, is some kind of way to define the "default number precision", feels a bit more high level... |
Integer literals are promoted to public static float Sweep(float x)
{
float offset = 1.0544;
float sweep = offset - Math.Cos(x / 4);
return Math.Sin(42 * sweep * (1 + (3 + Math.Sin(x * 350)) / 8));
} |
There seems to be no way to define a float inline (such as 1f or 1.f)
There is also no way to do type cast as far as I can tell (if there is, please add to documentation)
It's also a bit unclear how the auto-casting behaves, if you assign to a float, it always seem to make sure type is correct, but if you pass a float to Math.Sin, it does not (this actually causes compile error on c#)
However, For C/C#, ideally you want sinf/MathF if you pass a float to sin, and not to have it converted to double...
I guess it works like that automatically in C++ already since std::sin has both versions...
(I would also be fine with a separate prefix, so the fusion code would be explicit in which version you call, just like in c#)
(#83 seem to be a related issue)
The text was updated successfully, but these errors were encountered: