Is there a Ceil() Floor() in FB?
Joshy
Ceil() Floor() in FB?
-
- Posts: 8628
- Joined: May 28, 2005 3:28
- Contact:
Code: Select all
'' from "crt/math.bi"
extern "c"
declare function ceil (byval as double) as double
declare function floor (byval as double) as double
declare function ceilf (byval as single) as single
declare function ceill (byval as double) as double
declare function floorf (byval as single) as single
declare function floorl (byval as double) as double
end extern
-
- Posts: 8628
- Joined: May 28, 2005 3:28
- Contact:
Oh, now I see what you mean ...
Code: Select all
#define Floor(d) (Int(d))
#define Ceil(d) (-Int(-d))
-
- Posts: 8628
- Joined: May 28, 2005 3:28
- Contact:
Code: Select all
'cint_ceil_floor.bas
#macro SCW(i)
asm
sub esp,2
fnstcw [esp]
mov ax, [esp]
and ax, &HF3FF
or ax, &H0400
mov [i],ax
fldcw [i]
#endmacro
#macro RCW()
fldcw [esp]
add esp, 2
end asm
#endmacro
#macro CIntF(i,f)
asm fld dword ptr [f]
asm fistp dword ptr [i]
#endmacro
#macro CIntD(i,f)
asm fld qword ptr [f]
asm fistp dword ptr [i]
#endmacro
#macro CeilF(i,f)
SCW(i)
fld dword ptr [f]
fchs
fistp dword ptr [i]
neg dword ptr [i]
RCW()
#endmacro
#macro CeilD(i,d)
SCW(i)
fld qword ptr [d]
fchs
fistp dword ptr [i]
neg dword ptr [i]
RCW()
#endmacro
#macro FloorF(i,d)
SCW(i)
fld dword ptr [d]
fistp dword ptr [i]
RCW()
#endmacro
#macro FloorD(i,d)
SCW(i)
fld qword ptr [d]
fistp dword ptr [i]
RCW()
#endmacro
'
' main
'
dim as integer a,b,c
for f as single=0 to 3 step 0.333333
CIntF(a,f)
CeilF(b,f)
FloorF(c,f)
? a,b,c
next
?
for d as double=0 to 3 step 0.333333
CIntD(a,d)
CeilD(b,d)
FloorD(c,d)
? a,b,c
next
sleep