Author Topic: Floor Ceil ?  (Read 3242 times)

0 Members and 1 Guest are viewing this topic.

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Floor Ceil ?
« on: June 03, 2007 »
I cant seem to find the functions to do this.

Could someone tell me how to floor and ceil in FB pls?
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Floor Ceil ?
« Reply #1 on: June 03, 2007 »
Sorry, there's no fb commands for that.
Adding or subtracting 0.5 then converting to an int (and back if you need the result in a float) is what I've been doing although sometimes with unwanted results (try it with an odd whole number and an even whole number to see) so I find a value like 0.4999 to be a bit better.

Offline Merick

  • Atari ST
  • ***
  • Posts: 113
  • Karma: 7
    • View Profile
Re: Floor Ceil ?
« Reply #2 on: June 03, 2007 »
Actually, if you use the lua headers in your program you might be able use a pcall to access lua's math library, which does have those functions.

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Floor Ceil ?
« Reply #3 on: June 04, 2007 »
ok, thanks guys for the info :)
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Floor Ceil ?
« Reply #4 on: June 04, 2007 »
Use the ones in the C runtime library, crt.bi.

Jim
Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Floor Ceil ?
« Reply #5 on: June 04, 2007 »
thanx Jim, good idea.

I've also had a go at coding the functions too :D

Code: [Select]
Declare Function Floor( value as double )
Declare Function Ceil( value as double )

Function Floor( value as double )
   
dim newValue as integer
If ( value < 0 ) then
newValue = value - ( 1.0 - Abs(value Mod 1) )
Return newValue
Else
newValue = value - (value Mod 1)
Return newValue
EndIf
   
End Function

Function Ceil( value as double  )

dim newValue as integer
If ( value > 0 ) then
newValue = value + ( 1.0 - Abs(value Mod 1) )
Return newValue
Else
newValue = value - (value Mod 1)
Return newValue
EndIf

End Function
« Last Edit: June 04, 2007 by Tetra »
Challenge Trophies Won: