zsh-workers
 help / color / mirror / code / Atom feed
* floating-point precision and zsh vs ksh93 and coreutils
@ 2022-03-23 16:36 Vincent Lefevre
  2022-03-27  8:26 ` Stephane Chazelas
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Lefevre @ 2022-03-23 16:36 UTC (permalink / raw)
  To: zsh-workers

For floating-point arithmetic evaluation, it appears that zsh uses the
"double" type while ksh93 and GNU coreutils both use the "long double"
type, which means incompatibility:

$ ksh93 -c '/usr/bin/printf "%a\n" $((1./3))'
0xa.aaaaaaaaaaaaa9ep-5
$ zsh -fc '/usr/bin/printf "%a\n" $((1./3))'
0xa.aaaaaaaaaaaa74ep-5

and

$ ksh93 -c '/usr/bin/printf "%a\n" $((43./2**22))'
0xa.cp-20
$ zsh -fc '/usr/bin/printf "%a\n" $((43./2**22))'
0xa.c0000000000025cp-20

In the second case, while the number is exactly representable
(and has the same value) in both double and long double, the
issue is visible because the number is passed with a decimal
representation, with enough decimal digits to read the result
with 53-bit precision in the zsh test.

Shouldn't zsh switch to long double?

Note: using printf from the GNU coreutils instead of the zsh printf
builtin is needed for %a support.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-07 18:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23 16:36 floating-point precision and zsh vs ksh93 and coreutils Vincent Lefevre
2022-03-27  8:26 ` Stephane Chazelas
2022-03-27 22:26   ` Bart Schaefer
2022-04-07 15:06     ` Vincent Lefevre
2022-04-07 18:00       ` Bart Schaefer
2022-04-07 15:03   ` Vincent Lefevre

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).