|
From: Per W. <pw...@ia...> - 2005-06-27 12:59:47
|
2 raised to 8 is 256. Dividing by two is 128. 128+1 is 129.
Your compiler don't do wrong. You have to know what _you_ want before
putting requirements on the compiler.
The easiest way to get 128.5 is:
a = 128.5.
If you want a formula to evaluate to 128.5 for a specific variable value,
you have to explain what the formula should evaluate to reach the value
128.5 (or possibly -128.5).
/Per W
On Mon, 27 Jun 2005, Scott wrote:
> >I'm not sure how abs() would help.. unless that's to ensure that the
> >original value is positive before multiplying by negative one?
> >-Lukas
>
> This is still not working right,
> Iv'e been scratching my head on this all day..
>
> I'm trying to get the value of 128.5
> But instead all the mentioned formula's are giving me 129...
>
> What i'm trying to express is this..
>
> (2^8+1)/ 2 = 128.5
>
> So in C/C++ it should be pow(2,8)/2+1 (However it returns 129)
>
> Here is a quick test....
> ----------------------------------------------------------
> #include <stdio.h>
> #include <math.h>
> void main()
> {
> double test;
> test=pow(2,8)/2+1; //figure 2 to the eighth power +1
> printf("The number is %0.0f \n",test);
> system("PAUSE");
> return 0;
> }
> -----------------------------------------------------------
> #include <stdio.h>
> #include <math.h>
> void main()
> {
> float test;
> test=((2^8+1) / 2); //figure 2 to the eighth power +1
> printf("The number is %0.0f \n",test);
> system("PAUSE");
> return 0;
> }
> -------------------------------------------------------------
>
> Here is a quick snippett from the actual source code i'm using to position
> points.
>
> sprintf( cmd, "MAKEBOX <%g %g %g> <%g %g %f> <%d %d %d>",
> -128.5, -0.0, -128.5, pow(2,8)/2+1, 0.0, pow(2,8)/2+1, 1, 1, 1 );
> local->evaluate( local->data, cmd );
>
> Both suffer from the returning the same 129 figure....
> I must be missing something stupid... (i'll try again in the morning)
>
> Thanks for the help guys..
>
> Cheers,
> Scott.
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|