When I compile the program below, it throws up warnings about this statement:
because I'm trying to assign a Long Int from a Float.Code:loopspersec = lps / spd;
My question:
Is there any function to convert a float to an integer?
Code:#include <stdio.h> #include <time.h> #include <stdlib.h> #include <limits.h> #include <math.h> #define TOTAL_LOOPS 500000000 int main (void) { clock_t s, e; float spd, dur; long loopspersec; long lps; if( TOTAL_LOOPS > LONG_MAX) { printf("Hmmm, this shouldn't happen."); return -1; } s = clock(); for (lps = 0; lps < TOTAL_LOOPS; lps++ ); e = clock(); dur = e - s; spd = dur / CLOCKS_PER_SEC; loopspersec = lps / spd; printf ( "%ld Loops in %f seconds.\n", lps, spd ); printf ( "%ld Loops per second.\n", loopspersec); system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks



