🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.sys.palmtops.pilot
Article #199

Re: Mathlib functions always returning 0

#199
From: Logan Shaw
Date: Tue, 21 Oct 2003 03:19
43 lines
3131 bytes
Luc M. wrote:

> I get '0' from a mathlib functions when I try to pass a parameter.
> The functions return the proper value if the parameter is checked before
> calling the function.
> 
> Assuming 'index' is equal to 2, why does the function 'sqrt(index)' return 0
> in the following code:
> 
>    Int32 index;
>    double c;
> 
>    index = StrAToI(FldGetTextPtr(fldInput));     /* field set so that index
> is 2 */
>    c = sqrt(index);                                              /* Returns
> 0 ? */
> 
> 
> But it returns the proper value in the following code:
> 
>     index = StrAToI(FldGetTextPtr(fldInput));   /* field set so that index
> is 2 */
>     if(index == 2)
>     {
>       c = sqrt(index);                                          /* Returns
> proper value !!! */
>     }

I don't know why, but my advice is to disassemble the compiler's
output.  Something funny is going on.  Maybe one piece of code
ends up with index as a register variable and the other doesn't
or something along those lines.

Obviously, you also want to be sure that you have included some
.h file with a prototype for sqrt(), because if you haven't, it
will be passing in values as if they're ints, in which case I think
the behavior is undefined.

Also, it might help to go through your code with a debugger and be
sure that the value of index really is 2 just before the call to
sqrt(), because maybe something unexpected is happening before then.

   - Logan
Technical Details
Message-ID: <XA1lb.87131$7_1.14126@twister.austin.rr.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newspeer1.nwr.nac.net!newspeer.monmouth.com!newshosting.com!news-xfer2.atl.newshosting.com!167.206.3.103.MISMATCH!news3.optonline.net!cyclone.rdc-nyc.rr.com!news-west.rr.com!news.rr.com!cyclone.austin.rr.com!twister.austin.rr.com.POSTED!53ab2750!not-for-mail
References: <7Q0lb.2265$aw5.156000@news20.bellglobal.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11219a,9fa37096d9ae1ba3
X-Google-Attributes: gid11219a,public
X-Google-Thread: 109e18,9fa37096d9ae1ba3
X-Google-Attributes: gid109e18,public
X-Google-Thread: 10baa0,9fa37096d9ae1ba3
X-Google-Attributes: gid10baa0,public
X-Google-Thread: 112073,9fa37096d9ae1ba3
X-Google-Attributes: gid112073,public
X-Google-ArrivalTime: 2003-10-20 20:19:18 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newspeer1.nwr.nac.net!newspeer.monmouth.com!newshosting.com!news-xfer2.atl.newshosting.com!167.206.3.103.MISMATCH!news3.optonline.net!cyclone.rdc-nyc.rr.com!news-west.rr.com!news.rr.com!cyclone.austin.rr.com!twister.austin.rr.com.POSTED!53ab2750!not-for-mail
From: Logan Shaw <lshaw-usenet@austin.rr.com>
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5) Gecko/20031007
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: alt.comp.sys.palmtops.pilot,comp.sys.palmtops,comp.sys.palmtops.pilot,codewarrior.palm
Subject: Re: Mathlib functions always returning 0 
References: <7Q0lb.2265$aw5.156000@news20.bellglobal.com>
In-Reply-To: <7Q0lb.2265$aw5.156000@news20.bellglobal.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 44
Message-ID: <XA1lb.87131$7_1.14126@twister.austin.rr.com>
Date: Tue, 21 Oct 2003 03:19:19 GMT
NNTP-Posting-Host: 66.68.160.44
X-Complaints-To: abuse@rr.com
X-Trace: twister.austin.rr.com 1066706359 66.68.160.44 (Mon, 20 Oct 2003 22:19:19 CDT)
NNTP-Posting-Date: Mon, 20 Oct 2003 22:19:19 CDT
Organization: Road Runner - Texas