Post Reply 
Is super-accuracy matters?
10-11-2023, 12:21 AM (This post was last modified: 10-13-2023 04:52 PM by Albert Chan.)
Post: #16
RE: Is super-accuracy matters?
(10-09-2023 07:24 PM)johnb Wrote:  "how do you convince others that additional accuracy/precision is/is-not needed?"

It may be hard to show benefit, but we can go for how little cost it take.

Example, I recently upgraded old luajit 1.1.8 with openlibm, for better accuracy.
Old luajit was using msvcrt.dll FSIN/FCOS/FPTAN, with only 68 bits of pi
see Intel Underestimates Error Bounds by 1.3 quintillion

Code:
                OLD       NEW = luajit + openlibm
luajit.exe    48142     48142
lua51.dll    283662    351758
mathx.dll     35342         0
complex.dll   34830         0   
-----------------------------
             401976    399900

Adding openlibm code to luajit (*) does not bloat up dll's.
(and, no cheating! libopenlibm.a is a static library)

I don't quite understand how angle reduction code work, but result is amazing!
Performance is OK, see Accurate trigonometric functions for large arguments

lua> x = 1e22
lua> sin(x), dtoh(x)
-0.8522008497671888             +0x1.0f0cf064dd592p+73
lua> !spigot --printf "%.17g" sin(0x1.0f0cf064dd592p+73)
-0.8522008497671888

lua> x = 1e308
lua> sin(x), dtoh(x)
0.4533964905016491             +0x1.1ccf385ebc8a0p+1023
lua> !spigot --printf "%.17g" sin(0x1.1ccf385ebc8a0p+1023)
0.45339649050164912

Last 2 numbers actually matched. luajit use dtoa-fast for numeric output.
Default is output minimum digits that round-trip, same as python 3.

(*) the reason math related code move *inside* lua is due to mingw compiler design.
If openlibm is *inside* lua51.dll, its code should get picked first, before msvcrt.dll



Luajit 1.1.8, -O2 or higher, use hardware FSIN/FCOS/FPTAN for speed.
Below patch would remove this optimization, and use libm versions instead.

ljit_x86.h add sin/cos/tan (exact order!) partially inlined math functions. (patch in bold)
Then, remove jit_inline_math() sin/cos/tan cases, and use default (libm) instead.

ljit_x86.h Wrote:/* Partially inlined math functions. */
/* CHECK: must match with jit_hints.h and jit.opt_lib. */
// ALBERT: sin/cos/tan use libm too, 10-11-2023
static const mathfunc_11 jit_mathfuncs_11[JIT_IH_MATH_SIN + 3] = {
log, log10, exp, sinh, cosh, tanh, asin, acos, atan, sin, cos, tan
};

Proper way is to patch ljit_x86_inline.dash, then auto-generate ljit_x86.h
But, that required working lua is available.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Is super-accuracy matters? - Albert Chan - 10-06-2023, 04:36 PM
RE: Is super-accuracy matters? - Jlouis - 10-06-2023, 04:42 PM
RE: Is super-accuracy matters? - Jlouis - 10-06-2023, 05:05 PM
RE: Is super-accuracy matters? - EdS2 - 10-07-2023, 07:00 AM
RE: Is super-accuracy matters? - EdS2 - 10-07-2023, 07:24 AM
RE: Is super-accuracy matters? - KeithB - 10-24-2023, 01:33 PM
RE: Is super-accuracy matters? - vaklaff - 10-24-2023, 03:38 PM
RE: Is super-accuracy matters? - johnb - 10-24-2023, 03:46 PM
RE: Is super-accuracy matters? - johnb - 10-09-2023, 07:12 PM
RE: Is super-accuracy matters? - Johnh - 10-08-2023, 04:37 AM
RE: Is super-accuracy matters? - johnb - 10-09-2023, 07:24 PM
RE: Is super-accuracy matters? - Albert Chan - 10-11-2023 12:21 AM
RE: Is super-accuracy matters? - dm319 - 10-13-2023, 03:08 PM
RE: Is super-accuracy matters? - dm319 - 10-10-2023, 07:33 PM
RE: Is super-accuracy matters? - KeithB - 10-13-2023, 03:21 PM
RE: Is super-accuracy matters? - johnb - 10-13-2023, 03:36 PM
RE: Is super-accuracy matters? - johnb - 10-14-2023, 03:38 AM
RE: Is super-accuracy matters? - KeithB - 10-13-2023, 08:57 PM
RE: Is super-accuracy matters? - DA74254 - 10-20-2023, 07:02 AM
RE: Is super-accuracy matters? - mfleming - 10-20-2023, 12:07 PM
RE: Is super-accuracy matters? - EdS2 - 10-20-2023, 08:55 AM
RE: Is super-accuracy matters? - johnb - 10-20-2023, 04:40 PM
RE: Is super-accuracy matters? - Johnh - 10-20-2023, 07:48 PM
RE: Is super-accuracy matters? - dm319 - 10-30-2023, 11:46 AM
RE: Is super-accuracy matters? - EdS2 - 10-20-2023, 09:06 PM
RE: Is super-accuracy matters? - EdS2 - 10-24-2023, 05:20 PM
RE: Is super-accuracy matters? - EdS2 - 11-18-2023, 09:13 AM
RE: Is super-accuracy matters? - klesl - 11-18-2023, 09:24 AM
RE: Is super-accuracy matters? - Johnh - 11-18-2023, 11:11 AM
RE: Is super-accuracy matters? - johnb - 11-20-2023, 11:41 PM
RE: Is super-accuracy matters? - nickapos - 11-18-2023, 05:24 PM
RE: Is super-accuracy matters? - Pekis - 11-19-2023, 08:44 PM
RE: Is super-accuracy matters? - klesl - 11-18-2023, 01:53 PM



User(s) browsing this thread: 1 Guest(s)