9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Problem with native vs APE math
@ 2000-07-31  5:22 Doug Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Doug Henderson @ 2000-07-31  5:22 UTC (permalink / raw)
  To: 9fans

Here is my example program, running on a Celeron 400MHz. with the June 17
release. I have built it in native mode (mk, 8c, 8l) and in the APE
environment. It works when built in APE (and also, with minor mods in
linux). The native mode executable suicides during the log(0.0L) call:
edemo 355: sys: fp: invalid fppc=0x1391 pc=0x00001050

The library code looks ok. It should return -Inf for log(0) and NaN for
log(-1), which is what the APE does.

Any ideas?

#ifdef _POSIX_SOURCE
#include <stdio.h>
#include <math.h>
#else
#include <u.h>
#include <libc.h>
#include <stdio.h>
#endif
int main(int argc, char* argv[])
{
 printf("log(1.0) = %f\n", log(1.0L));
 printf("log(0.0) = %f\n", log(0.0L));
 printf("log(-1.0) = %f\n", log(-1.0L));
 return 0;
}
--  --
Doug Henderson, Calgary, Alberta, Canada




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

* Re: [9fans] Problem with native vs APE math
  2000-07-31  6:27 Russ Cox
@ 2000-07-31 14:40 ` Doug Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Doug Henderson @ 2000-07-31 14:40 UTC (permalink / raw)
  To: 9fans

On my Celeron, I get log(1)=0, log(0)=-HUGE_VAL and log(-1)=-HUGE_VAL, which
is what I expect from reading the code for log in
/sys/src/ape/lib/ap/math/log.c, and errno is set to ERANGE for log(0) and
EDOM for log(-1).

Clearing the FPINVAL bit in the pcr gets rid of the suicides.

There is an undocumented bit set in psr after log(0).
Also, there is a mismatch between some defines in ape/float.h and
ape/sys/fp.h

----- Original Message -----
From: "Russ Cox" <rsc@plan9.bell-labs.com>
To: <djhender@telusplanet.net>; <9fans@cse.psu.edu>
Sent: Monday, July 31, 2000 12:27 AM
Subject: Re: [9fans] Problem with native vs APE math


> When I compile that using APE I get 0.00000
> for all the answers, which is not what I expected
> but not unreasonable given the code.
> I don't think that the APE libraries use Inf and NaN.
>
> As for why it crashes natively, you need to
> turn off some exceptions related to use of
> Inf and NaN -- see getfcr(2).
>
> Russ
>




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

* Re: [9fans] Problem with native vs APE math
@ 2000-07-31  6:27 Russ Cox
  2000-07-31 14:40 ` Doug Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Russ Cox @ 2000-07-31  6:27 UTC (permalink / raw)
  To: djhender, 9fans

When I compile that using APE I get 0.00000
for all the answers, which is not what I expected
but not unreasonable given the code.
I don't think that the APE libraries use Inf and NaN.

As for why it crashes natively, you need to
turn off some exceptions related to use of
Inf and NaN -- see getfcr(2).

Russ


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

end of thread, other threads:[~2000-07-31 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-31  5:22 [9fans] Problem with native vs APE math Doug Henderson
2000-07-31  6:27 Russ Cox
2000-07-31 14:40 ` Doug Henderson

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