RosettaCodeData/Task/Active-object/FreeBASIC/active-object.basic

28 lines
663 B
Plaintext

#define twopi 6.2831853071795864769252867665590057684
dim shared as double S = 0 'set up the state as a global variable
dim shared as double t0, t1, ta
function sine( x as double, f as double ) as double
return sin(twopi*f*x)
end function
function zero( x as double, f as double ) as double
return 0
end function
sub integrate( K as function(as double, as double) as double, f as double )
'represent input as pointers to functions
t1 = timer
s += (K(t1,f) + K(t0,f))*(t1-t0)/2.0
t0 = t1
end sub
t0 = timer
ta = timer
while timer-ta <= 2.5
if timer-ta <= 2 then integrate( @sine, 0.5 ) else integrate( @zero, 0 )
wend
print S