% Program caused arithmetic error: Floating illegal operand [message #90935] |
Thu, 14 May 2015 16:39  |
jiaxinxin
Messages: 4 Registered: May 2014
|
Junior Member |
|
|
I have this code :
xc=250 & yc=250 & r=170 & for i=yc-r , yc+r do print,floor(-sqrt(1.*r^2-1.*(i-yc)^2)+xc)
if charge r=185 , i get the fllowing error:
% Program caused arithmetic error: Floating illegal operand
I don't konw what to do to get rid of this error. Do you have any ideas?
|
|
|
Re: % Program caused arithmetic error: Floating illegal operand [message #90936 is a reply to message #90935] |
Thu, 14 May 2015 18:29  |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
On Thursday, 14 May 2015 16:39:39 UTC-7, jiaxinxin wrote:
> I have this code :
> xc=250 & yc=250 & r=170 & for i=yc-r , yc+r do print,floor(-sqrt(1.*r^2-1.*(i-yc)^2)+xc)
> if charge r=185 , i get the fllowing error:
> % Program caused arithmetic error: Floating illegal operand
> I don't konw what to do to get rid of this error. Do you have any ideas?
Yes, your value 'r' is a short integer, so notice what happens to r^2:
IDL> 170^2
28900
IDL> 185^2
-31311
I will guess that this is not what you wanted. I'd suggest using float values, at least for 'r' and 'c' (which looks like it could give trouble, too). Then you can get rid of the "1.*", which I guess was to change the expression to float.:
xc=250 & yc=250. & r=185. & for i=yc-r , yc+r do print,floor(-sqrt(r^2-(i-yc)^2)+xc)
You might find it useful to put these values in an array, which can be done easily like this. (I think IDL 8.0 is needed to use the [start:end] syntax I use here):
xc=250 & yc=250. & r=185. & myResult = floor(-sqrt(r^2-([yc-r:yc+r]-yc)^2)+xc)
(running "PLOT, myResult" after this shows a very nice semicircle!)
Also, good job with presenting your question clearly, with all the important details! Not everyone has been as clear in the past few days. :-)
Cheers,
-Dick
Dick Jackson Software Consulting Inc.
Victoria, BC, Canada --- http://www.d-jackson.com
|
|
|