9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Charles Forsyth <forsyth@terzarima.net>
To: 9fans@9fans.net
Subject: Re: [9fans] compiler double bug.
Date: Tue,  1 Dec 2009 22:19:24 +0000	[thread overview]
Message-ID: <d893fc0b1d0b52a1dd610d7eb14279d3@terzarima.net> (raw)
In-Reply-To: <dc10137c2661c11595d2aa2ca370ba45@brasstown.quanstro.net>

oh! getival is yours? but it's in the changes on the - lines not the + lines.
the diffs have crossed the equator!
i think i understand now.

so the original had statements such as:
		wc = (int)getfval(x);
and for excessive values in x (that couldn't be represented as an int)
there was a trap. that seems consistent with the behaviour defined below:

6.3.1.4 Real floating and integer

When a finite value of real floating type is converted to integer type other than _Bool,
the fractional part is discarded (i.e., the value is truncated toward zero). If the value of
the integral part cannot be represented by the integer type, the behavior is undefined.[footnote 41]

[41] The remaindering operation performed when a value of integer type is converted to unsigned type
   need not be performed when a value of real floating type is converted to unsigned type. Thus, the
   range of portable real floating values is (−1, Utype_MAX+1).


so getival returning uint or ulong (or unsigned something-big-enough) avoids
the problem and seems fine to me.

there is, however, a bug in the compiler elsewhere, in that a suitable (uint) cast in a
direct assignment
	int x = (uint)doubleval;
is (apparently) discarded by the compiler, and it shouldn't be.
that shouldn't affect your getival cases, though.



  parent reply	other threads:[~2009-12-01 22:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <<a4d2df97e4d97d460ae33ca0800a4060@terzarima.net>
2009-12-01 18:41 ` erik quanstrom
2009-12-01 21:35   ` Charles Forsyth
2009-12-01 22:19   ` Charles Forsyth [this message]
     [not found] <<d5e75e65219a1207aad92a000119dba0@terzarima.net>
2009-12-02  1:59 ` erik quanstrom
     [not found] <<d893fc0b1d0b52a1dd610d7eb14279d3@terzarima.net>
2009-12-01 22:31 ` erik quanstrom
2009-12-01 23:33   ` Charles Forsyth
     [not found] <<0232aa110f8423b8381e009b6cda7cef@terzarima.net>
2009-12-01 21:45 ` erik quanstrom
     [not found] <<dc10137c2661c11595d2aa2ca370ba45@brasstown.quanstro.net>
2009-12-01 18:53 ` erik quanstrom
     [not found] <<615bb2c21f211025b5d9aba799fffe0d@terzarima.net>
2009-12-01 16:39 ` erik quanstrom
2009-12-01 17:02   ` Charles Forsyth
2009-12-01 16:39 ` erik quanstrom
     [not found] <<9987774388a28369b01fa5658da35af9@terzarima.net>
2009-12-01 15:05 ` erik quanstrom
2009-12-01 16:31   ` Charles Forsyth
     [not found] <<2d42b6b28807634253ba28dc55a96de6@brasstown.quanstro.net>
2009-12-01  8:02 ` erik quanstrom
2009-12-01  9:43   ` Charles Forsyth
2009-12-01  9:45     ` Charles Forsyth
2009-12-01  7:55 erik quanstrom

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=d893fc0b1d0b52a1dd610d7eb14279d3@terzarima.net \
    --to=forsyth@terzarima.net \
    --cc=9fans@9fans.net \
    /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.
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).