<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Programing question in Libraries &amp; objects</title>
    <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77732#M39231</link>
    <description>Peter&lt;BR /&gt;
&lt;BR /&gt;
I was wondering if there was a certain situation this was coming from, that maybe there would be some kind of logic that would prevent it from happening. Since objects should probably never have an A or B value of 0, that should kickj up an error if its own.</description>
    <pubDate>Fri, 10 Dec 2004 01:44:13 GMT</pubDate>
    <dc:creator>TomWaltz</dc:creator>
    <dc:date>2004-12-10T01:44:13Z</dc:date>
    <item>
      <title>Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77727#M39226</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;&lt;T&gt;What is the best bit of code to use to avoid "divide by zero" errors?&lt;BR /&gt;
I run into this issue often when using circular functions&lt;BR /&gt;
such as in the following piece of code.&lt;BR /&gt;
&lt;BR /&gt;
ratio=b/a&lt;BR /&gt;
ang=atn(ratio)&lt;BR /&gt;
&lt;BR /&gt;
If "a" happens to be zero there is an error.&lt;BR /&gt;
Usually I resort to placing the following at the&lt;BR /&gt;
beginning of the script.&lt;BR /&gt;
&lt;BR /&gt;
if a=0 then a=0.0000001&lt;BR /&gt;
&lt;BR /&gt;
This "work-around" is logically very dissatisfying to me.&lt;BR /&gt;
Is there a better way?&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Peter Devlin&lt;/T&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Dec 2004 21:09:32 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77727#M39226</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-12-09T21:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77728#M39227</link>
      <description>&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;IF A &amp;lt;&amp;gt; 0 THEN
     ratio=b/a
     ang=atn(ratio)
ELSE
   (something to fix the problem)
ENDIF&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Dec 2004 22:16:04 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77728#M39227</guid>
      <dc:creator>TomWaltz</dc:creator>
      <dc:date>2004-12-09T22:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77729#M39228</link>
      <description>Tom,&lt;BR /&gt;
Thank you for your reply.&lt;BR /&gt;
Its the "(something to fix the problem)"&lt;BR /&gt;
that I was looking for.&lt;BR /&gt;
Something more elegant than if a=0 then a=0.00000001.&lt;BR /&gt;
Peter</description>
      <pubDate>Thu, 09 Dec 2004 22:45:22 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77729#M39228</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-12-09T22:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77730#M39229</link>
      <description>Where are A and B coming from?</description>
      <pubDate>Thu, 09 Dec 2004 23:59:00 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77730#M39229</guid>
      <dc:creator>TomWaltz</dc:creator>
      <dc:date>2004-12-09T23:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77731#M39230</link>
      <description>Tom,&lt;BR /&gt;
In the example I gave "a" and "b" are the obligatory &lt;BR /&gt;
x and y dimensions of a library part.&lt;BR /&gt;
But they could be any numeric parameter or variable &lt;BR /&gt;
that has a possible value of zero either as initialized or&lt;BR /&gt;
as the result of calculation.&lt;BR /&gt;
Peter</description>
      <pubDate>Fri, 10 Dec 2004 00:47:40 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77731#M39230</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-12-10T00:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77732#M39231</link>
      <description>Peter&lt;BR /&gt;
&lt;BR /&gt;
I was wondering if there was a certain situation this was coming from, that maybe there would be some kind of logic that would prevent it from happening. Since objects should probably never have an A or B value of 0, that should kickj up an error if its own.</description>
      <pubDate>Fri, 10 Dec 2004 01:44:13 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77732#M39231</guid>
      <dc:creator>TomWaltz</dc:creator>
      <dc:date>2004-12-10T01:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77733#M39232</link>
      <description>Tom,&lt;BR /&gt;
I appreciate your interest in this issue.&lt;BR /&gt;
I made a library part that is a detail marker.&lt;BR /&gt;
 (see attached image)&lt;BR /&gt;
I wanted (0,0) to be at the center of the "bubble"&lt;BR /&gt;
and the point (a,b) to be at the edge of the call-out symbol&lt;BR /&gt;
so that the connecting line between bubble and symbol&lt;BR /&gt;
can be stretched to any angle and length and&lt;BR /&gt;
still point to the center of the bubble similar to&lt;BR /&gt;
what Red was trying to do in the thread titled "tangent".&lt;BR /&gt;
The code must allow the library part's "A" to equal zero &lt;BR /&gt;
to display the shape labeled  #2&lt;BR /&gt;
I know that there are ways to code this part so that&lt;BR /&gt;
"A" equaling zero does not cause a problem, but&lt;BR /&gt;
this is not the point I only use this lib part as an&lt;BR /&gt;
example of where one value divides another value&lt;BR /&gt;
and the dividing value may equal zero &lt;BR /&gt;
and therefor cause an error.&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Peter</description>
      <pubDate>Fri, 10 Dec 2004 02:47:53 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77733#M39232</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-12-10T02:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77734#M39233</link>
      <description>I don't have a more efficient solution. Usually, when I know that a divisor can became zero, I use the following form:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;epsilon = 0.000001&lt;/B&gt; ! &amp;lt;--at the beginning of the current (or Master) Script&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;ratio=b/MAX(a, epsilon) &lt;BR /&gt;
ang=atn(ratio)&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
This way the error message can be avoided.&lt;BR /&gt;
But, if the number can also be negative, the formula has to be more complex. ... I think something like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;ratio=b / (MAX(ABS(a), epsilon) * (sgn(a)+(a=0)))&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
 &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_eek.gif" style="display : inline;" /&gt; GASP! &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_surprised.gif" style="display : inline;" /&gt; &lt;BR /&gt;
_______________________________&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;FONT color="red"&gt;--&lt;/FONT&gt;&lt;FONT color="darkblue"&gt;Roberto Corona&lt;/FONT&gt;&lt;FONT color="red"&gt;--&lt;/FONT&gt;</description>
      <pubDate>Fri, 10 Dec 2004 10:09:55 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77734#M39233</guid>
      <dc:creator>rocorona</dc:creator>
      <dc:date>2004-12-10T10:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77735#M39234</link>
      <description>&lt;BLOCKQUOTE&gt;rocorona wrote:&lt;BR /&gt;I don't have a more efficient solution. Usually, when I know that a divisor can became zero, I use the following form:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;epsilon = 0.000001&lt;/B&gt; ! &amp;lt;--at the beginning of the current (or Master) Script&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;ratio=b/MAX(a, epsilon) &lt;BR /&gt;
ang=atn(ratio)&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
This way the error message can be avoided.&lt;BR /&gt;
But, if the number can also be negative, the formula has to be more complex. ... I think something like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;ratio=b / (MAX(ABS(a), epsilon) * (sgn(a)+(a=0)))&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
 &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_eek.gif" style="display : inline;" /&gt; GASP! &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_surprised.gif" style="display : inline;" /&gt; &lt;BR /&gt;
_______________________________&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;FONT color="red"&gt;--&lt;/FONT&gt;&lt;FONT color="darkblue"&gt;Roberto Corona&lt;/FONT&gt;&lt;FONT color="red"&gt;--&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;

Yes, this is similar to what GS programmers do in their GDL Scripts.&lt;BR /&gt;
One can check out any AC9 Door or Window script and will find many examples similar to this:&lt;BR /&gt;
&lt;BR /&gt;
IF ABS(Whatever) &amp;gt; EPS THEN&lt;BR /&gt;
    ...............&lt;BR /&gt;
ENDIF&lt;BR /&gt;
&lt;BR /&gt;
EPS is for Epsilon.</description>
      <pubDate>Fri, 10 Dec 2004 10:48:37 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77735#M39234</guid>
      <dc:creator>Laszlo Nagy</dc:creator>
      <dc:date>2004-12-10T10:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77736#M39235</link>
      <description>I have always preferred a 'logical check';&lt;BR /&gt;
&lt;BR /&gt;
&lt;FONT color="red"&gt;oEpsilon = 0.0000001&lt;BR /&gt;
ratio = oA / ( (oB=0) * Epsilon + oB )&lt;/FONT&gt;&lt;BR /&gt;
&lt;BR /&gt;
For angles this is extended to;&lt;BR /&gt;
&lt;BR /&gt;
&lt;FONT color="red"&gt;oAngle = atn ( oA / ( (oB=0) * Epsilon + oB)&lt;/FONT&gt;&lt;BR /&gt;
&lt;BR /&gt;
Oh how I wish we had 'proper' macro statements ...&lt;BR /&gt;
&lt;BR /&gt;
&lt;FONT color="red"&gt;oAngle = myATN (oA, oB)&lt;BR /&gt;
!------&lt;BR /&gt;
define macro "myATN" (value1, value2)&lt;BR /&gt;
return atn ( value1 / ( (value2=0) * 0.000001 + value2)&lt;/FONT&gt;&lt;BR /&gt;
&lt;BR /&gt;
- Stuart</description>
      <pubDate>Fri, 10 Dec 2004 11:07:58 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77736#M39235</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-12-10T11:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77737#M39236</link>
      <description>Instead of conditional change of 'a', why not simply change 'ang' directly?
&lt;PRE&gt;IF a&amp;lt;epsilon THEN ang=90&lt;/PRE&gt;

Stuart, wouldn't this code&lt;BR /&gt;
&lt;FONT color="red"&gt;ratio = oA / ( (oB=0) * Epsilon + oB ) &lt;/FONT&gt;&lt;BR /&gt;
trigger the annoying 'precision problems' warning?</description>
      <pubDate>Fri, 10 Dec 2004 16:19:03 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77737#M39236</guid>
      <dc:creator>Durval</dc:creator>
      <dc:date>2004-12-10T16:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77738#M39237</link>
      <description>Durval;&lt;BR /&gt;
&lt;BR /&gt;
I might be wrong, but IMHE, "x=0" doesn't seem to create a precision problem. x=1 (or any other number) can.&lt;BR /&gt;
&lt;BR /&gt;
Will test a little over the w/e.&lt;BR /&gt;
&lt;BR /&gt;
? - Stuart</description>
      <pubDate>Fri, 10 Dec 2004 18:52:47 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77738#M39237</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-12-10T18:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77739#M39238</link>
      <description>I would prefer:&lt;BR /&gt;
&lt;BR /&gt;
IF ABS(a)&amp;lt;EPS THEN ang=SGN(b)*90 ELSE ang=TAN(b/a)&lt;BR /&gt;
&lt;BR /&gt;
as imho it is more readable and clear</description>
      <pubDate>Fri, 10 Dec 2004 20:33:30 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77739#M39238</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2004-12-10T20:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Programing question</title>
      <link>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77740#M39239</link>
      <description>Hello,&lt;BR /&gt;
Looking at all of the replies to my original question I can only conclude&lt;BR /&gt;
that some conditional, somewhat arbitrary, change to the devisor must be made when the devisor acquires a zero value.&lt;BR /&gt;
At the time I posted my question I was wondering if there was some mathematical algorithm or programing command that would say in effect  &lt;BR /&gt;
if a=0 then &lt;BR /&gt;
a=(smallest non-zero quantity allowed by the program/math processor).&lt;BR /&gt;
I was thinking that in floating point arithmetic "zero" must have some&lt;BR /&gt;
internal definition limited by precision.&lt;BR /&gt;
Since I don't have a computer science background the above statements&lt;BR /&gt;
may be complete gibberish.&lt;BR /&gt;
This thread has certainly brought up some fascinating issues.&lt;BR /&gt;
Thank you all for your comments,&lt;BR /&gt;
Peter Devlin</description>
      <pubDate>Sat, 11 Dec 2004 03:25:49 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Libraries-objects/Programing-question/m-p/77740#M39239</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-12-11T03:25:49Z</dc:date>
    </item>
  </channel>
</rss>

