9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Riddler <riddler876@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Floating point and dividing by 0
Date: Fri, 18 Apr 2014 21:44:06 +0100	[thread overview]
Message-ID: <CAGMcHPrSvj+jwyfyf2zf0X9B68iJePcJ+mfVkxTLZOFUEvKFqw@mail.gmail.com> (raw)
In-Reply-To: <72d84d382ece571ee9be74a694b20d7d@ladd.quanstro.net>

[-- Attachment #1: Type: text/plain, Size: 1456 bytes --]

I'm using the standard plan9 kernel running in a 32bit i386 VirtualBox VM.
The fcr (printed with %ulb) was 1001000000 which seems to be FPPEXP and FPP
DBL.

Your code does indeed produce the expected output on my VM.

So if my kernel isn't really doing the right thin; and the 'expected'
behavior would be for my program to enter an infinite loop. Considering
that's not happening (and assuming I understand correctly), perhaps
something in notes/noted() needs looked at?


On Fri, Apr 18, 2014 at 9:10 PM, erik quanstrom <quanstro@quanstro.net>wrote:

> 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("");
> }
>
>

[-- Attachment #2: Type: text/html, Size: 2144 bytes --]

  reply	other threads:[~2014-04-18 20:44 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
2014-04-18 20:44   ` Riddler [this message]
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=CAGMcHPrSvj+jwyfyf2zf0X9B68iJePcJ+mfVkxTLZOFUEvKFqw@mail.gmail.com \
    --to=riddler876@gmail.com \
    --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).