[futurebasic] Re: [FB] House Management and C code (FB^3)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2001 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Fri, 26 Jan 2001 19:35:55 +1300
>>So Floor (5.4) would give 5, Ceiling (5.4) would give 6, I reckon.
>>
>>
>>FIX can handle any Floor situation, but INT can return 5 for 5.4 or 6 for
>>5.6, how might I make it or similar round up regardless?
>>
>>If I have this wrong, C interpretation -wise, clarification is welcome.

>is this what you want?


FIX is not the same as floor, and neither method posted so far for ceiling
is wholly satisfactory. The gold standard is set by the MathLib functions,
which can be called as shown in the demo below.

Robert P.


'-----run in Console mode------

local fn ceiling1(myNumber#)
dim myInt as long // added by RP
myInt = FIX(myNumber#)
if myInt < myNumber# then myNumber# = myInt + 1
end fn = myNumber#

DEF FN ceiling2(num#) = num# + 0.99998

#if cpuPPC
library "MathLib"
Toolbox ceil( long )
Toolbox floor( long )
library

local fn Ceil#( x as double )
beginassem
 lfd f1,^x
 _ceil
 stfd f1,^x
endassem
end fn = x

local fn Floor#( x as double )
beginassem
 lfd f1,^x
 _floor
 stfd f1,^x
endassem
end fn = x
#endif

gFBFloatMaxDigits = 13

local fn ShowCeils( x as double )
print "x          = " x
print "true ceil  = " fn Ceil#( x )
print "ceiling 1  = " fn ceiling1( x )
print "ceiling 2  = " fn ceiling2( x )
print
end fn

local fn ShowFloors( x as double )
print "x          = " x
print "true floor = " fn Floor#( x )
print "fix        = " fix( x )
print
end fn

fn ShowCeils(  1.1 )
fn ShowCeils( -1.1 )
fn ShowCeils(  1e10 + 0.5 )
fn ShowCeils( -1e10 - 0.5 )

fn ShowFloors(  1.1 )
fn ShowFloors( -1.1 )
'------------------------