zsh-workers
 help / color / mirror / code / Atom feed
From: Vincent Lefevre <vincent@vinc17.net>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org, Emanuel Berg <embe8573@student.uu.se>
Subject: Re: why do ceil/floor give the decimal dot?
Date: Mon, 18 May 2015 10:39:17 +0200	[thread overview]
Message-ID: <20150518083917.GB25036@ypig.lip.ens-lyon.fr> (raw)
In-Reply-To: <150514105426.ZM30800@torch.brasslantern.com>

On 2015-05-14 10:54:26 -0700, Bart Schaefer wrote:
> No, I mean that looking at this:
> 
> torch% float X=27
> torch% print $X
> 2.700000000e+01
> torch% print $(( X ))
> 27.
> torch% printf "%f\n" $X        
> 27.000000
> torch% printf "%g\n" $X
> 27
> 
> One might wonder why there are four different representations of the
> same number, and we could therefore discuss whether some of them should
> be unified.  This is not the same discussion as whether they should be
> converted to integers.

Concerning the accuracy:

ypig% float x=$((1./3))
ypig% print $x
3.333333333e-01
ypig% print $((x))
0.33333333333333331
ypig% printf "%f\n" $x
0.333333
ypig% printf "%g\n" $x
0.333333

The last two are specified by C, and I suppose that $((x)) gives full
accuracy, i.e. if the decimal number is re-read as a floating-point
value, the original value must be recovered exactly.

Concerning the first one, I wonder why there are "typeset -E" (default
for "float" as used above) and "typeset -F". The way a value is output
shouldn't come from its declaration. IMHO, there should be a single
floating-point datatype, not one for each output format.

BTW, there is a bug in zsh 5.0.7:

ypig% typeset -F 3 x=$((17))
ypig% print $x
17.000
ypig% typeset -F 2 x=$((17))
ypig% print $x              
17.00
ypig% typeset -F 1 x=$((17))
typeset: invalid base (must be 2 to 36 inclusive): 1

It is not a base here.

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


  reply	other threads:[~2015-05-18  8:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-14  0:32 Emanuel Berg
2015-05-14  2:56 ` Bart Schaefer
2015-05-14  3:29   ` Emanuel Berg
2015-05-14  3:53     ` Lawrence Velázquez
2015-05-14  9:53       ` Peter Stephenson
2015-05-14 21:38         ` Emanuel Berg
2015-05-14 22:14           ` Lawrence Velázquez
2015-05-14 23:29             ` Emanuel Berg
2015-05-15  0:46             ` Oliver Kiddle
2015-05-15  1:07               ` Emanuel Berg
2015-05-15  1:27               ` Bart Schaefer
2015-05-18  8:16             ` Vincent Lefevre
2015-05-14  4:04     ` Bart Schaefer
2015-05-14  9:12       ` Emanuel Berg
2015-05-14 17:54         ` Bart Schaefer
2015-05-18  8:39           ` Vincent Lefevre [this message]
2015-05-18  9:41             ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150518083917.GB25036@ypig.lip.ens-lyon.fr \
    --to=vincent@vinc17.net \
    --cc=embe8573@student.uu.se \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).