12 Commits

Author SHA1 Message Date
Damian Schneider
a421a90e0a
replacement for fastled sqrt16() (#4426)
* added bitwise operation based sqrt16

- replacement for fastled, it is about 10% slower for numbers smaller 128 but faster for larger numbers. speed difference is irrelevant to WLED but it saves some flash.

* updated to 32bit, improved for typical WLED use

- making it 32bits allows for larger numbers
- added another initial condition check for medium sized numbers
- increased the "small number" optimization to larger numbers: the function is currently only used to calculate sqrt(x^2+y^2) which even for small segments is larger than the initially used 64, so optimizing for 1024 makes more sense, although the value is arbitrarily chosen
2025-01-20 05:51:04 +01:00
Damian Schneider
4cd0563a93 changed 90° offset to hex, fixed potential bug in FX using sin/cos with incrementing number
- sin/cos calls with incrementing numbers can lead to bad outcomes, the functions (_approx or original sinf/cosf) return bad values for very large float inputs
2024-11-27 21:53:32 +01:00
Damian Schneider
1a8aaa3b26 Speed improvements, commented legacy _t trig functions
- speed improvement: by default M_TWOPI is treated as a double float
- directly calling sin16_t in cos_approx() saves a lot of overhead
2024-11-26 20:32:39 +01:00
Damian Schneider
98a6907976 cleanup and improvement to sin_appros()
-replaced all PI references with M_PI version
-there is no need to do the angle-modulo in float, casting it to an integer does the same BUT it has to be cast to an `int` first, see comment.
2024-10-16 19:53:58 +02:00
Damian Schneider
5e29f2c1b7 fixed atan2_t
approximation was incorrect, now doing it right.
also removed hypotf() from octopus, saving a little flash.
2024-10-15 20:11:33 +02:00
Damian Schneider
f301296f1e added rounding to sin8_t
thx to @softhack007
2024-10-06 21:27:58 +02:00
Damian Schneider
7b855c851d Added integer based sin()/cos() functions, changed all trig functions to wled_math
- `sin16_t() / cos16_t()` are faster and more accurate than fastled versions
- `sin_approx() / cos_approx()` are float wrappers for `sin16_t() / cos16_t()` and are accurate enough to replace `sinf()/cosf()`
- `atan2()` is used only in octopus to calculate center offset, new approximated version saves flash
- `tan(), atan(), asin(), acos(), floor(), fmod()` are used only for sunrise/sunset calculation, using wled_math version saves flash
- `beatsinx()` replacements are to make use of new `sin16_t()/sin8_t()` functions to reduce flash size
- Extensively tested surnise/sunset calculation: deviation is 1min. max
- Tested some of the relevant FX and found no visual difference: Julia, 2D Drift, Drift Rose, Ghost rider, Rotozoomer, Palette, Arc 1D expansion
- total flash savings: 7.4k
2024-10-05 12:32:41 +02:00
Frank
da0cf01eee fixing a few implicit promotions to double
any expression with at least on "double" is evaluated as double, which is slow.
2023-09-09 20:48:17 +02:00
Blaž Kristan
506b6b51ce whitespace cleanup 2023-01-06 09:24:29 +01:00
Blaz Kristan
c14f16bdf1 Merge branch 'master' into master-merge 2022-03-19 21:05:28 +01:00
Blaz Kristan
d4ea30e081 Merge branch 'master' into merge-master 2022-02-10 14:16:55 +01:00
Blaž Kristan
5714578783 Refactoring & code clean-up.
- utility functions
- network functions
- math functions
2021-10-11 14:13:34 +02:00