Loading...
Pages: [1]   Go Down
Author Topic: pow how  (Read 325 times)
0 Members and 1 Guest are viewing this topic.
Norway
Offline Offline
Sr. Member
****
Karma: 4
Posts: 422
microscopic quantum convulsions of space-time
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was going to post a bug suggestion, but then I realized that the "pow()" function returns a double precision number.

I was going insane over this not returning expected integer (or byte) values:
Code:
greenByte = (byte)pow(2,rowCounter) ;  // green testpattern

It worked until it should return values above 2... it should be 1,2,4,8,16...etc but instead it returned 1,2,3,7,15,31....

This fixed that, and also made the compiled code almost 2k shorter:
Code:
   greenByte = 1;
    for(int i=0;i<rowCounter;i++) greenByte *= 2;

I just wanted to mention that, in case others have similar problems. I guess it is not a bug, just some inaccuracies due to it being a double precision (kind of a counterintuitive name in this respect though  smiley-razz )

Oh, and the hightlight in the IDE for the pow() function still isnt fixed, but I guess thats a minor, minor flaw.
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 129
Posts: 10383
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe you can shorten it even further with this...

Code:
greenByte = 1 << rowCounter;
« Last Edit: October 18, 2009, 11:51:01 pm by bcook » Logged

Norway
Offline Offline
Sr. Member
****
Karma: 4
Posts: 422
microscopic quantum convulsions of space-time
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Coding Badly: Great, thanks! You don't live up to your name  smiley
Logged

Pages: [1]   Go Up
Print
 
Jump to: