zsh-workers
 help / color / mirror / code / Atom feed
* Floating-point arithmetic evaluation on Linux/x86 (traditional FPU)
@ 2007-11-12 14:54 Vincent Lefevre
  2007-11-12 16:41 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Lefevre @ 2007-11-12 14:54 UTC (permalink / raw)
  To: zsh-workers

The zshmisc man page says:

ARITHMETIC EVALUATION
  The  shell  can  perform  integer and floating point arithmetic, either
  using the builtin let, or via a substitution of the form $((...)).  For
  integers,  the  shell is usually compiled to use 8-byte precision where
  this is available, otherwise precision is 4 bytes.  This can be tested,
  for example, by giving the command `print - $(( 12345678901 ))'; if the
  number appears unchanged, the precision is at least 8 bytes.   Floating
  point arithmetic is always double precision.

But it is not true that zsh always uses double precision. It seems to
use the C double type, but this doesn't correspond to double precision
by default under Linux/x86 (when the traditional FPU is used, i.e. no
SSE2). For instance, I get:

vin:~> uname -a
Linux vin 2.6.22-1-686-bigmem #1 SMP Sun Jul 29 15:54:01 UTC 2007 i686 GNU/Linux
vin:~> echo $((9007199254740994.0+(1.0-1/65536.0)-9007199254740994.0))
2.

instead of "0." on other machines, due to the "double rounding"
effect. More information about this problem on:

  http://www.vinc17.org/research/extended.en.html

Either zsh should switch to double precision (assuming that modules
and so on won't change the precision back to the extended precision),
or the zsh documentation should be changed.

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


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

end of thread, other threads:[~2007-11-12 16:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-12 14:54 Floating-point arithmetic evaluation on Linux/x86 (traditional FPU) Vincent Lefevre
2007-11-12 16:41 ` Peter Stephenson

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).