Strange code, with great float number

edited June 2016 in Questions about Code

This is strange. If the increment for a big float variable is 63, the variable seem that remain the same. If the increment for a big float variable is 64, the variable change. Why??

float timeBase = 1466271360;

void setup() {}

void draw() {

    timeBase = timeBase + 63; //This doesn't increment timebase, result is always lower
    //timeBase = timeBase + 64; //This increment timeBase, result is always grater

    if(timeBase > 1466271360){
    else {


  • edited June 2016 Answer ✓

    You're almost reaching int's MAX_INT threshold: println(MAX_INT); // 2147483647
    Much probably it has already blown float's MAX_FLOAT by now: println(MAX_FLOAT); // 3.4028235E38

    You're better off upgrading it to double: double timeBase = 1466271360d;. >-)
    Or if you don't need the fractional part, stick w/ int: int timeBase = 1466271360; ;;)

  • thanks!

Sign In or Register to comment.