Notice: A non well formed numeric value encountered in /sites/rockbox.org/flyspray/includes/class.flyspray.php on line 96 Notice: A non well formed numeric value encountered in /sites/rockbox.org/flyspray/includes/class.flyspray.php on line 96 Notice: A non well formed numeric value encountered in /sites/rockbox.org/flyspray/includes/class.flyspray.php on line 96 Deprecated: Function create_function() is deprecated in /sites/rockbox.org/flyspray/includes/class.flyspray.php on line 104 Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /sites/rockbox.org/flyspray/adodb/adodb.inc.php on line 845 Deprecated: Function create_function() is deprecated in /sites/rockbox.org/flyspray/includes/class.user.php on line 111 FS#11229 : FFT: math rework

# Rockbox

## FS#11229 - FFT: math rework

Attached to Project: Rockbox
Opened by Delyan Kratunov (archivator) - Wednesday, 28 April 2010, 21:45 GMT
Last edited by Andree Buschmann (Buschel) - Wednesday, 12 May 2010, 02:42 GMT
Task Type Patches Plugins Closed No-one All players Low Normal Release 3.4 Undecided Undecided 0 No

### Details

Simplifies the math routines, removes all 64-bit math and unused 64-bit math sqrt function.

Closed by  Andree Buschmann (Buschel)
Wednesday, 12 May 2010, 02:42 GMT
Reason for closing:  Accepted
Comment by Bertrik Sikken (bertrik) - Thursday, 29 April 2010, 07:09 GMT
Just a quick note. It seem that in some cases you're first calculating a square root and then taking the logarithm. This can probably combined more efficiently (haven't tested it though):
* just take the logarithm without doing the square root first
* divide the result by 2
This uses the mathematical property log(x^a) = a log (x), where a = 0.5 in this case
Comment by Delyan Kratunov (archivator) - Thursday, 29 April 2010, 12:30 GMT
While that's technically true, I can't see how to use it here. Let me explain:

Before the if (tmp>0) bit, tmp is at most 29 bits (an assumption made throughout the code). The sqrt call makes sure that it's at most 14 bits, so that the right shift does not overflow.

If I don't do the sqrt, the right shift is virtually guaranteed to overflow, which is what this refactoring is trying to fix.
If I don't do the right shift at all but just leave the log call (it *is* in theory a linear mapping), values < 0xFFFF will be treated as less than 1, resulting in negative and quite large values for tmp - obviously not the desired outcome. Therefore, the right shift is needed and therefore, the sqrt call is needed to guarantee that the shift does not overflow.

If I'm missing something, do let me know.
Comment by Delyan Kratunov (archivator) - Thursday, 29 April 2010, 12:30 GMT
Sorry, that should say left shift, obviously.
Comment by Andree Buschmann (Buschel) - Tuesday, 11 May 2010, 20:01 GMT
Wasn't this submitted with r25790?
Comment by Delyan Kratunov (archivator) - Tuesday, 11 May 2010, 20:07 GMT
It was. I don't have the necessary privileges on FS to close the task (and frankly, I forgot about it :) )