提交 f697d66b 编写于 作者: N nsz

math: change the formula used for acos.s

old: 2*atan2(sqrt(1-x),sqrt(1+x))
new: atan2(fabs(sqrt((1-x)*(1+x))),x)
improvements:
* all edge cases are fixed (sign of zero in downward rounding)
* a bit faster (here a single call is about 131ns vs 162ns)
* a bit more precise (at most 1ulp error on 1M uniform random
samples in [0,1), the old formula gave some 2ulp errors as well)
上级 db4096c5
# use acos(x) = atan2(fabs(sqrt((1-x)*(1+x))), x)
.global acosf .global acosf
.type acosf,@function .type acosf,@function
acosf: acosf:
...@@ -14,17 +16,13 @@ acosl: ...@@ -14,17 +16,13 @@ acosl:
.type acos,@function .type acos,@function
acos: acos:
fldl 4(%esp) fldl 4(%esp)
1: fld1 1: fld %st(0)
fld %st(1)
fld1 fld1
fsubp fsub %st(0),%st(1)
fsqrt fadd %st(2)
fxch %st(2) fmulp
faddp
fsqrt fsqrt
fabs # fix sign of zero (matters in downward rounding mode)
fxch %st(1)
fpatan fpatan
fld1
fld1
faddp
fmulp
ret ret
# see ../i386/acos.s
.global acosl .global acosl
.type acosl,@function .type acosl,@function
acosl: acosl:
fldt 8(%rsp) fldt 8(%rsp)
1: fld %st(0)
fld1 fld1
fld %st(1) fsub %st(0),%st(1)
fld1 fadd %st(2)
fsubp fmulp
fsqrt
fxch %st(2)
faddp
fsqrt fsqrt
fabs
fxch %st(1)
fpatan fpatan
fld1
fld1
faddp
fmulp
ret ret
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册