9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] Floating point and dividing by 0
Date: Fri, 18 Apr 2014 16:10:58 -0400	[thread overview]
Message-ID: <72d84d382ece571ee9be74a694b20d7d@ladd.quanstro.net> (raw)
In-Reply-To: <CAGMcHPqONnwf6gB2ajEGseA2FE6fxjvJ4V6+zr2pr7kQUP3NYg@mail.gmail.com>

i imagine what happened is your kernel doesn't really do the right thing
on catching the exception.  i think the caught exception should restart
the program *exactly* where it left off, dividing by zero, which will lead
to an infinite loop.  if your kernel skipped the instruction, then the value
of (in my case r) would be whatever the previous value was.  if this is the
statement that initializes r, this could be random trash on the stack.  which
would lead to a mystery exception later on for some value of trash on stack.

- erik
----

this provides the correct result.

#include <u.h>
#include <libc.h>

void
main(void)
{
	double zero, r;

	setfcr(getfcr() & ~FPZDIV);

	zero = 0.;
	r = 1.;
	r = r/zero;
	print("%g\n", r);
	exits("");
}



  parent reply	other threads:[~2014-04-18 20:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-18 19:52 Riddler
2014-04-18 19:56 ` erik quanstrom
2014-04-18 20:10 ` erik quanstrom [this message]
2014-04-18 20:44   ` Riddler
2014-04-18 20:54     ` erik quanstrom
2014-04-18 21:32       ` Riddler
2014-04-18 21:39         ` 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=72d84d382ece571ee9be74a694b20d7d@ladd.quanstro.net \
    --to=quanstro@quanstro.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).