* Why does this code dont work on Alpha?
@ 2000-01-05 5:00 Pete
2000-01-05 5:00 ` Phillip Helbig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Pete @ 2000-01-05 5:00 UTC (permalink / raw)
I wonder why I get
Floating point exception (core dumped)
then I run this very simple C code?
main()
{
float x = 3.14;
long i;
for (i=0;i<1000000000;i++)
x=x*x;
}
It runs fine on both Solaris and Linux. Dont
know why it fails on the 21164-600 (EV56) with
Digital Unix 4.0F and DEC Alpha cc
One strange thing is that if I loop only 10 times
it runs fine, but with 100 or more loops it fails.
- Pete
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Why does this code dont work on Alpha? 2000-01-05 5:00 Why does this code dont work on Alpha? Pete @ 2000-01-05 5:00 ` Phillip Helbig 2000-01-05 5:00 ` Joe Mario 2000-01-05 5:00 ` Andreas Krall 2 siblings, 0 replies; 4+ messages in thread From: Phillip Helbig @ 2000-01-05 5:00 UTC (permalink / raw) In article <84vbos$v43$1@inet-1.pnu.com>, Pete <pete@no-spam.net> writes: > I wonder why I get > Floating point exception (core dumped) > then I run this very simple C code? > > main() > { > float x = 3.14; > long i; > for (i=0;i<1000000000;i++) > x=x*x; > } > > It runs fine on both Solaris and Linux. ^^^^^^^^^ You need to think about what that really means. Here's the traceback from a VMS system (21064A, DEC C V6.0-001 on OpenVMS Alpha V7.2-1, but these facts are not crucial here). %SYSTEM-F-HPARITH, high performance arithmetic trap, Imask=00000000, Fmask=00000 001, summary=08, PC=00000000000200C4, PS=0000001B -SYSTEM-F-FLTOVF, arithmetic trap, floating overflow at PC=00000000000200C4, PS= 0000001B %TRACE-F-TRACEBACK, symbolic stack dump follows image module routine line rel PC abs PC TEST TEST main 6 00000000000000C4 00000000000200C4 TEST TEST __main 0 0000000000000068 0000000000020068 0 FFFFFFFF82A913D4 FFFFFFFF82A913D4 It's pretty obvious that you're getting overflow. (I REALLY like the fact that /DEBUG=(TRACEBACK,NOSYMBOLS) is the default on VMS.) Yes, some other systems don't notice the overflow, `run fine' and produce garbage. I would rather have a program crash than run wrongly. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why does this code dont work on Alpha? 2000-01-05 5:00 Why does this code dont work on Alpha? Pete 2000-01-05 5:00 ` Phillip Helbig @ 2000-01-05 5:00 ` Joe Mario 2000-01-05 5:00 ` Andreas Krall 2 siblings, 0 replies; 4+ messages in thread From: Joe Mario @ 2000-01-05 5:00 UTC (permalink / raw) Pete wrote: > I wonder why I get > Floating point exception (core dumped) > then I run this very simple C code? > > main() > { > float x = 3.14; > long i; > for (i=0;i<1000000000;i++) > x=x*x; > } > The reason it fails is that when "i" reaches 7, the value of "x" is greater than what can be represented in a float type. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Why does this code dont work on Alpha? 2000-01-05 5:00 Why does this code dont work on Alpha? Pete 2000-01-05 5:00 ` Phillip Helbig 2000-01-05 5:00 ` Joe Mario @ 2000-01-05 5:00 ` Andreas Krall 2 siblings, 0 replies; 4+ messages in thread From: Andreas Krall @ 2000-01-05 5:00 UTC (permalink / raw) In article <84vbos$v43$1@inet-1.pnu.com>, Pete <pete@no-spam.net> writes: > I wonder why I get > Floating point exception (core dumped) > then I run this very simple C code? > ... > for (i=0;i<1000000000;i++) > x=x*x; ... You get a floating point exception because the result of your computation is to big to be represented as a floating point number (3.14^2^100000000). If you want to do floating point coumputations with infinities you have to compile your program with the option -ieee. Your result will then be a positive infinity. -- andi@complang.tuwien.ac.at Andreas Krall http://www.complang.tuwien.ac.at/andi/ Inst. f. Computersprachen, TU Wien tel: (+431) 58801/18511 Argentinierstr. 8/4/1851 fax: (+431) 58801/18598 A-1040 Wien AUSTRIA EUROPE ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2000-01-05 5:00 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2000-01-05 5:00 Why does this code dont work on Alpha? Pete 2000-01-05 5:00 ` Phillip Helbig 2000-01-05 5:00 ` Joe Mario 2000-01-05 5:00 ` Andreas Krall
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox