Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
jostapo

Broken sin and cos functions?

Recommended Posts

Try the following code snippet:

_blah = sin 180

player globalchat format["SIN180 is: %1",_blah]

It should be 0 but is returning -8.74.  If you run:

_blah = sin 180.1

player globalchat format["SIN180 is: %1",_blah]

It returns the correct answer just off 0.

This is running 1.91 of the beta patch.  Can anyone at bis shed a little light on this?  Many of the functions and scripts CoC is currently using use cardinal compass headings, and these results are a little alarming.

Thanks,

Jostapo, aka Joel

I should add that both SIN and COS both misbehave on cardinal compass headings. SIN being correct for 90 and 270, and COS being correct for 0 and 180.

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (jostapo @ Mar. 31 2003,08:19)</td></tr><tr><td id="QUOTE">_blah = sin 180

player globalchat format["SIN180 is: %1",_blah]

It should be 0 but is returning -8.74.<span id='postcolor'>

I tried this:

player globalchat format["SIN180 is: %1",sin 180]

The result was:

-8.74228e-008

Which I think is acceptable error, caused probably by numeric errors, esp. when converting from degrees to radians.

Share this post


Link to post
Share on other sites

It's not returning -8. It's returning some number so close to zero, that OFP's engine can't display it properly. I think that's why it's returning that strange string --> -8.74428e-008

-0.00000000874428 <---EDIT This is the number it's really returning.

Try this and you'll see:

hint format["%1",(sin 180) - 1]

This code will also give you the same result (-1)

hint format["%1",(-0.00000000874428 - 1)]

Share this post


Link to post
Share on other sites

Sorry.  I've been up all night tinkering on MLRS special effects and Cruise missile guidance scripts... and stumbled over that problem in some debug lines I had.

It freaked me out for a minute as I thought we'd have to revisit a lot of code.

Just goes to show you that all night coding sessions can lead to little ASSumptions.

Thanks and sorry for wasting your time guys.

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (toadlife @ Mar. 31 2003,08:51)</td></tr><tr><td id="QUOTE">It's not returning -8. It's returning some number so close to zero, that OFP's engine can't display it properly. I think that's why it's returning that strange string --> -8.74428e-008

-0.00000000874428  <---EDIT This is the number it's really returning.<span id='postcolor'>

What strange thing? confused.gif -8.74428e-008 is no strange thing. I hope you did not intend to start a flame war on this poor number wow.gif . -8.74428e-008  is normal real number in "scientific" notation used commonly in computers and even calculators. wink.gif It can be read as -8.74428 * 10^-8, i.e. -8.74428 * 0.00000001. tounge.gif

Share this post


Link to post
Share on other sites

I used to develop exlusively in VC++ and should have remembered the string formatting. Lately all I've been working in is Delphi, VB, or .net stuff... and each of those languages has a way of 'dumbing down' the floating point displays.

I thought the - was a seperator!

I promise to flog myself duly.

Share this post


Link to post
Share on other sites

well, the supersmall number has the advantage that cos/sin functions don't give a divide by zero error.

Share this post


Link to post
Share on other sites

So much for my CoC mates being supporting.

Bn880 sucks! (kidding)

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (jostapo @ Mar. 31 2003,17:22)</td></tr><tr><td id="QUOTE">So much for my CoC mates being supporting.

Bn880 sucks! (kidding)<span id='postcolor'>

Don't you mean supportive? lol tounge.gif j/k

Share this post


Link to post
Share on other sites

Hi all

Jostapo april fooled him self Mu Ha

The best bit was he advertised his error in the developers forum biggrin.gif

Kind Regards to you Joel assumptions huh.

PS by the way the problem with our forum is the backups our ISP made to protect our data when the upgraded the DB a couple of hundred of them! In Each table! crazy.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×