[futurebasic] Re: [FB] Some C to FB

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2013 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Sun, 9 Jun 2013 14:54:40 -0700
Robert Covington wrote:

> particularly the  lines 57 and 58?


> Are those a logical comparison? adding 1 if true?
> 
> 
> 
> 
> 57	            i = i - (int)i + (i < 0.);


'(int)’ is casting the i ( or j in line 58 both lines are the same but different vars )  variable to an int.

'(i < 0. )' is a logical comparison of i ( a double ) with '0.' ( which is a way to compare a double/float var to zero ). The logical expression returns zero or one. So as a whole it says "take the i variable and subtract the int (cast) version of i from i and add the result of the logical expression ( zero or one ) to i.

Other than C style 'for' loops, the rest of this code is simple calculations that look mostly the same in FB code. The ternary (three arguments ) operator on line 77 is an exception. In this case dstdata is set at the calculated subscript with '1.' if 'p > threshold' is true. If 'p > threshold' is false, the array at that subscript is set to '0.' In FB this would be written:

if ( p > threshold ) then dstdata[y * w + x] = 1. else dstdata[y * w + x] = 0.


Brian S.