comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » % Program caused arithmetic error: Floating illegal operand
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: % Program caused arithmetic error: Floating illegal operand [message #90936 is a reply to message #90935] Thu, 14 May 2015 18:29 Go to previous message
Dick Jackson is currently offline  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
[Message index]
 
Read Message
Read Message
Previous Topic: Copy file to all subfolders
Next Topic: Map an image onto a sphere

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:57:51 PDT 2025

Total time taken to generate the page: 0.00449 seconds