Re: Aw: Re: Re: deco-Math project, step 00_a: exact bin and dec 'ranges' (in gnumeric).



Alas on 7/5/21 7:39 PM, I wrote in part:

Beware that some library functions don't behave as expected. For 
example, on my machine, sqrt(2.) does not throw the FE_INEXACT 
exception.

That's just completely wrong.  Sorry.

  FWIW: I got fooled by a compiler optimization, but that's
  no excuse. I should have known better. I've been seeing
  compiler bugs, but that's not one of them. The fPU traps
  and flags work just fine.

==========================

Here's a program that allows you to explore and demonstrate
FPU behavior:

   https://www.av8n.com/cgit/FPU/tree/fpu_exceptions.c

The first few lines of the usage message are:
Typical usage:
  :; ./fpu_exceptions sqrt -1           # invalid (flag, not trap)
  :; ./fpu_exceptions +div div 1.1 0    # divide by zero (trap)
  :; ./fpu_exceptions +all div 1.1 0    # inexact trap happens before the divide
  :; ./fpu_exceptions pow 2 1024        # overflow AND inexact (flags, not traps)

* Interesting verb phrases include:
  help            # print this message (and immediately exit)
  atof 1.1        # FE_INEXACT
  div 1.1 0       # FE_DIVBYZERO (we clear the inexact flag before the div)
  div 1 10        # FE_INEXACT
  div 100 89      # FE_INEXACT
  div 5 10        # OK
  sqrt 2          # FE_INEXACT
  sqrt 4          # OK
  pow 2 1024      # FE_OVERFLOW | FE_INEXACT
  pow 3 34        # FE_INEXACT
                  # the power is calculated by iterative multiplication;
                  # it you turn on traps it will tell you how many
                  # iterations succeeded.

======================

You can clone the whole thing via:
  :; git clone https://www.av8n.com/cgit/FPU

Compile it using the makefile provided, or simply
  :;  ./fpu_exceptions.c
since it's a self-compiling source file
(assuming a reasonably conventional linux environment).


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]