Post Reply 
HP-15c Overflow question
08-27-2021, 09:03 PM
Post: #3
RE: HP-15c Overflow question
Intersestingly, modern computer may have wider exponent range for intermediate calculations.

Code:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    double x = strtod(argv[1], NULL);
    double y = strtod(argv[2], NULL);
    printf("x, y = %g, %g\n", x, y);
    printf("x/(x*x+y*y) = %g\n", x/(x*x+y*y));
    return 0;
}

> test 1e200 1e220
x, y = 1e+200, 1e+220
x/(x*x+y*y) = 1e-240

> test 1e-200 1e-220
x, y = 1e-200, 1e-220
x/(x*x+y*y) = 1e+200

Without the wider exponent range, 1st example underflow to 0, 2nd overflow to Inf

lua> function f(x,y) return x / (x*x+y*y) end
lua> f(1e200, 1e220)
0
lua> f(1e-200, 1e-220)
Inf

see Problems due to wider expoenent range
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP-15c Overflow question - agarza - 08-27-2021, 01:21 PM
RE: HP-15c Overflow question - rprosperi - 08-27-2021, 07:14 PM
RE: HP-15c Overflow question - agarza - 08-28-2021, 12:07 AM
RE: HP-15c Overflow question - Albert Chan - 08-27-2021 09:03 PM
RE: HP-15c Overflow question - C.Ret - 08-28-2021, 06:13 AM
RE: HP-15c Overflow question - agarza - 08-28-2021, 06:54 PM



User(s) browsing this thread: 1 Guest(s)