zsh-workers
 help / color / mirror / code / Atom feed
* wrong value for pi?
@ 2008-07-30 12:54 Julius Plenz
  2008-07-30 13:13 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Julius Plenz @ 2008-07-30 12:54 UTC (permalink / raw)
  To: zsh-workers

Hi!

Playing around, I noticed that Z-Shell wrongly evaluates the
expression "4.0*atan(1)" (which is equal to pi):

    zsh> zmodload zsh/mathfunc
    zsh> typeset -F 48 pi='4.0*atan(1)'
    zsh> echo $pi
    3.141592653589793115997963468544185161590576171875
                     ^- here the first error occurs

Is this indended, a bug or just owing to some sort of optimization or some C
library's shortcomings?

Julius


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

* Re: wrong value for pi?
  2008-07-30 12:54 wrong value for pi? Julius Plenz
@ 2008-07-30 13:13 ` Peter Stephenson
  2008-08-02  0:54   ` Vincent Lefevre
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2008-07-30 13:13 UTC (permalink / raw)
  To: zsh-workers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 977 bytes --]

Julius Plenz wrote:
> Hi!
> 
> Playing around, I noticed that Z-Shell wrongly evaluates the
> expression "4.0*atan(1)" (which is equal to pi):
> 
>     zsh> zmodload zsh/mathfunc
>     zsh> typeset -F 48 pi='4.0*atan(1)'
>     zsh> echo $pi
>     3.141592653589793115997963468544185161590576171875
>                      ^- here the first error occurs
> 
> Is this indended, a bug or just owing to some sort of optimization or some C
> library's shortcomings?

It's simply a question of what double precision actually gives on your
system, as it says in the manual (" Floating point arithmetic always
uses the ‘double’ type with whatever corresponding precision is
provided by the compiler and the library.").  Beyond that the digits
will certainly be gobbledygook.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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

* Re: wrong value for pi?
  2008-07-30 13:13 ` Peter Stephenson
@ 2008-08-02  0:54   ` Vincent Lefevre
  0 siblings, 0 replies; 3+ messages in thread
From: Vincent Lefevre @ 2008-08-02  0:54 UTC (permalink / raw)
  To: zsh-workers

On 2008-07-30 14:13:21 +0100, Peter Stephenson wrote:
> It's simply a question of what double precision actually gives on your
> system, as it says in the manual (" Floating point arithmetic always
> uses the ???double??? type with whatever corresponding precision is
> provided by the compiler and the library.").  Beyond that the digits
> will certainly be gobbledygook.

In fact, the digits should be correct for the double precision number
(i.e. after rounding).

BTW, zsh could optionally use MPFR. :)

-- 
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] 3+ messages in thread

end of thread, other threads:[~2008-08-02  0:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-30 12:54 wrong value for pi? Julius Plenz
2008-07-30 13:13 ` Peter Stephenson
2008-08-02  0:54   ` 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).