**1**

###
#22
Members - Reputation: **109**

Posted 22 May 2012 - 10:52 AM

You're not calculating the sin of PI... you're calculating the sin of (float)pi, or (double)pi. PI, as a whole, can't be represented as a float or even a double.

That's correct, that he is not calculating cos(pi/2), he is calculating cos((float)(pi/2)). But what I think is really cool (and what my post on randomascii discusses) is exactly what *is* being calculated, because it turns out to be very meaningful.

When you calculate sin((float)pi)) or cos((float)(pi/2)) then a bit of calculus or geometric reasoning shows that what you are actually calculating is the error in the value that you are passing in! Thus:

sin((float)pi); equals pi-float(pi) -- the error in (float)pi

cos((float)(pi/2)); equals pi/2-(float)(pi/2) - the error in (float)(pi/2)

The Cos and sin functions are extremely accurate and the result is typically accurate to about seven significant digits, so the real meaning of the result is that (float)(pi/2) is about -4.37114e-008 away from pi/2. This happens to be close to FLT_EPSILON, but while that is probable it is not, in general, necessarily true.

Cool!

This claim is not generically true, It is true for cos/sin around these values because the derivative at those points is 1 and because the 'expected' value is zero.

**Edited by BruceDawson, 22 May 2012 - 11:12 AM.**

###
#23
Members - Reputation: **646**

Posted 24 May 2012 - 04:27 AM

const float imopi = 0.017453292519943295769236907684886;

so then you should write this Cos = cos( angle* imopi);

https://sites.google.com/site/customprog/

###
#24
Members - Reputation: **962**

Posted 24 May 2012 - 06:39 AM

const float imopi = 0.017453292519943295769236907684886;

Not only has the problem been well-diagnosed to be

*not this*, but (appropriately enough) that constant has far more digits of precision than are typically representable in a float.

###
#25
Members - Reputation: **387**

Posted 24 May 2012 - 09:21 AM

The irrationality of pi is not exactly what the problem is. There are many rational numbers that cannot be expressed exactly in floating-point formats either, like 1/3 or 0.1.

Edit: sicrane brought me up to speed with your logic regarding 0.1. It's all obvious now that what does not possess infinite non-zero placeholders right of the decimal point in base 10 may have infinite non-zero placeholders right of the binary point in base 2. Thanks!

I vote for the next version of IEEE fp to be in base pi. Problem solved! I'm kidding.

###
#28
Members - Reputation: **589**

Posted 24 May 2012 - 04:34 PM

if you used the minimal epsilon you would end up with earth quite missing its real place.

###
#29
Crossbones+ - Reputation: **16261**

Posted 24 May 2012 - 04:40 PM

remember that float can provide certian exactness to computations against some extend. so if you need to get to very low extends, you should linear reduce those extends..... if you want to cumpute angle of earth against its eclipse (the plane that earths orbits the sun, thus 0 degrees exactly), you would have to provide sin (0)... you will never continue with this result unless you apply special data type or special routine of fractionizing the linear space to linear space power.

if you used the minimal epsilon you would end up with earth quite missing its real place.

I didn't get any of that. What's an "extend"? And what's wrong with computing sin(0)? What on Earth is "fractionizing the linear space to linear space power"?

###
#30
Members - Reputation: **589**

Posted 24 May 2012 - 06:44 PM

What on Earth is "fractionizing the linear space to linear space power"?

Good question. Think about amount of angles of earths sun orbit to its eclipse(plane between earth and sun).

Perfect 0.0.

But you do not never not know exact number, whatever it seems exact...... So "if eclipse of earth is identical to eclipse of earth", it may be volating some amount, hard to measure exact. Numbers can contain many information, the most exponsive information is information about the angle (never ending)

###
#31
Moderators - Reputation: **18055**

Posted 24 May 2012 - 06:52 PM

Let's keep this thread to the point, shall we?

[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]

###
#32
Crossbones+ - Reputation: **7003**

Posted 24 May 2012 - 07:00 PM

No offense, but... YOU'RE NOT MAKING ANY SENSE.

What on Earth is "fractionizing the linear space to linear space power"?

Good question. Think about amount of angles of earths sun orbit to its eclipse(plane between earth and sun).

Perfect 0.0.

But you do not never not know exact number, whatever it seems exact...... So "if eclipse of earth is identical to eclipse of earth", it may be volating some amount, hard to measure exact. Numbers can contain many information, the most exponsive information is information about the angle (never ending)

[edit]

I wrote this while ApochPiQ was posting... I'm done here.

**Edited by Cornstalks, 24 May 2012 - 07:01 PM.**

###
#34
Moderators - Reputation: **18055**

Posted 24 May 2012 - 07:26 PM

*ecliptics*which are hardly the same thing).

I have no idea how you consider that

*on*topic.

[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]