HackerN64 / HackerSM64

A Super Mario 64 decompilation repo based on CrashOveride95/ultrasm64 that aims to provide a flexible, easy-to-use base for creating romhacks.
340 stars 158 forks source link

Add More Math Util Functions #360

Open gheskett opened 2 years ago

gheskett commented 2 years ago

Notable function additions:

Maybe also consider adding inline functions for stuff like clamp, sign, min, max, etc.

thecozies commented 2 years ago

also roundf should be renamed to lroundf so that it can be used in constants

thecozies commented 2 years ago

https://github.com/FreyaHolmer/Mathfs/blob/master/Mathfs.cs#L811

example of some helpful funcs

Mr-Wiseguy commented 2 years ago

pow should be powf and log should be logf to conform with C standard library naming (https://en.cppreference.com/w/c/numeric/math/pow and https://en.cppreference.com/w/c/numeric/math/log). However, they won't be able to be evaluated at constant time like cozies said because of the repo using -ffreestanding as a compiler flag. There are ways around it, such as using __builtin_powf if the value is a constant.

Mr-Wiseguy commented 2 years ago

Here's an example of using __builtin_logf for constant evaluation: https://godbolt.org/z/33Ph9j4b8

Mr-Wiseguy commented 2 years ago

Here's a link to a repo with some fast approximate math function implementations, some of them use bit twiddling on floats so they're pretty fast: https://github.com/pmineiro/fastapprox

gheskett commented 2 years ago

Thoughts on supporting hash tables?

Mr-Wiseguy commented 2 years ago

I think hash tables are out of place in the repo because they would need to go hand-in-hand with a memory allocation scheme. A general hash function on the other hand could be nice, xxHash is a good option for that imo: https://github.com/Cyan4973/xxHash

gheskett commented 2 years ago

Moving to 2.2