-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Zeda/f24
bugfix for f24amean and f24geomean
- Loading branch information
Showing
2 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,49 @@ | ||
;!! Note !! | ||
; This has numerical issues in that it is directly computing the the product, | ||
; then the square root. This can cause overflow when it shouldn't (note that as | ||
; long as both inputs are finite, the output should be strictly finite). There | ||
; is a slower and more difficult algorithm that can and probably should be made. | ||
|
||
#ifndef included_f24geomean | ||
#define included_f24geomean | ||
|
||
#include "f24mul.z80" | ||
#include "f24sqrt.z80" | ||
|
||
f24geomean: | ||
;sqrt(AHL*BDE) ==> AHL | ||
;sqrt(AHL*CDE) ==> AHL | ||
|
||
;return NaN if the product is negative | ||
xor c | ||
jp p,+_ | ||
ld a,$7F | ||
ld h,a | ||
ret | ||
_: | ||
|
||
;the product is positive, so we can just set the inputs to positive | ||
xor c | ||
and $7F | ||
ret z ;may as well exit if the input is 0 | ||
cp $7F | ||
jr z,f24geomean_sub | ||
ld b,a | ||
|
||
ld a,c | ||
and $7F | ||
ret z | ||
cp $7F | ||
jr z,f24geomean_sub | ||
|
||
;now calculate the output exponent | ||
add a,b | ||
rra | ||
push af | ||
|
||
ld a,63 | ||
ld c,a | ||
adc a,0 | ||
call f24geomean_sub | ||
pop bc | ||
add a,b | ||
sub 63 | ||
ret | ||
|
||
f24geomean_sub: | ||
call f24mul | ||
jp f24sqrt | ||
#endif |