|
From: andrey <ak...@bk...> - 2005-06-27 13:53:55
|
(2^8+1)/ 2 isn't pow(2,8)/2+1
try
double test = (pow(2.0,8.0)+1.0)/2.0;
it will give you 128.5 because compiler know each value in expression DOUBLE
(sorry for my english)
Andrey
>
> >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
>
|