Closed arthurdenner closed 1 year ago
The main reason why I implemented real single floats (which directly use single floats on the C side and not clipped doubles) is that the PlayStation 2 is unable to process doubles by hardware, it needs to use software functions, which ends up causing considerable losses when dealing with tens or hundreds of floats in a loop.
For instance
Rendering with double floats:
Rendering with single floats:
I got more 5 FPS, and my code sample use a few floats, imagine that difference from hundreds.
I tried exploring Math.fround returning real singles. But I didn't like to create a double and after that cutting it into a single, I can have more performance just creating singles from the variable declaration.
I can edit Math.fround to return real singles, so you can handle with Float32 type without breaking format extensions, I think that's a fair solution, what do you think about it?
I think it's a fair tradeoff since it's a specific runtime, I like the idea 👍🏽
@DanielSant0s if every decimal number must be in 32bits, why not always convert to single? This would avoid using the math API or f
suffix.
It breaks numbers semantics
@arthurdenner I finished Math.fround implement. https://github.com/DanielSant0s/AthenaEnv/commit/792b7332bb36a3597bcef3900516abc5a5d00e8a
That's really good news. Thanks for the update!
From the README:
While I get the reason behind it, I'd like to mention that this approach breaks JavaScript tools such as ESLint and Prettier.
Of course, these tools are not critical but it'd be nice to have them (and possibly others like TypeScript) supported like in any other JavaScript project. I Google'd a bit and discovered the
Math.fround
method, which:In the same page, it mentions that:
As I'm not so familiar with single floats and lower-level languages, I was wondering if you have explored this approach as a replacement for the
f
suffix and if there are any drawbacks.I tried using this method in the dashboard and pong files which then could be formatted by Prettier for example. I didn't see an increase of memory usage but as the demos are simple, that's probably not a valid test case.