
Post by tsh73 on Nov 5, 2022 19:32:54 GMT
EDIT *I had a forum glitch making me think I lost that post. So I recreated it with more info, look below*
sometimes then your program calculates functions involving powers it breaks with error "Float underflow exception"
What is it? It is condition happening then math results goes somewhere under 1e300. Here how you can get one:
y=10.0^308 print y
(powers up to 307 works OK in this case)
Is it supposed to mean something? I dunno, some other languages just allow such small a number change to 0.0
How to fix/ avoid it? enclose offending part in a function catch error with on error return 0 if it is indeed "Float underflow exception"
Here's an example pi = acs(1) h=pi/300 t=25*h
'print (cos(6*t)*cos(18*t))^10 'dies with Float underflow exception 'now wrap that in a function and catch error there print y(t)
end
function y(t) on error goto [catch] 'y = 1/5*(cos(6*t)*cos(18*t))^10 y = 10.1^500
exit function [catch] if Err$="Float underflow exception" then y = 0:exit function 'else die naturally on error goto 0 resume '  will not do, loops 'print Err, Err$ end end function



Post by tsh73 on Nov 5, 2022 20:07:44 GMT
Float underflow exception: what is it and how to cope Sometimes program involving math (drawing wonderful plots for example) dies with "Float underflow exception". What is it? it is a notinn that result of calculation got out of limits presentable bu Double data type And it goues out of limits not in "big" part but rather very very close to 0. Here it is: print 10.0 ^307 'still OK print 10.0 ^308 'Float underflow exception Now, does it supposed to mean something? I dunno some languages I tried just silently change result to 0.0 If you are trying to draw interesting plot, that (rather then breaking the program) would be desired behavior. So how to avoid it? * wrap offending calculation in a function * catch error there * return 0 Now, you can catch this very error and return 0, or break program (: END) otherwise. (like in example y(t) does) Or you can just catch error and ignore it (like in example y2(t) does) For *this* error, it would default to returning 0 But in case you ever get other types of error ( divide by zero, float oveflow, argument of a function out of range ) program will just return 0. And you'll never know that So I'd rather use longer method, just in case. pi = acs(1) h=pi/300 t=25*h
print (cos(6*t)*cos(18*t)) '0.11329165e30, really really small
'print (cos(6*t)*cos(18*t))^10 'dies with Float underflow exception
'now, wrap that in a function, catch error there, return 0 print y(t) print y2(t)
function y(t) on error goto [catch] y = 1/5*(cos(6*t)*cos(18*t))^10 exit function [catch] if Err$="Float underflow exception" then y = 0: exit function 'else die print Err, Err$ end end function
function y2(t) on error goto [catch] y = 1/5*(cos(6*t)*cos(18*t))^10 exit function [catch] 'ignore error 'it returns 0 by default end function
Now, the program I found it in justbasiccom.proboards.com/thread/916/parametricplotmaple

