Must do things this way instead as DSMan195276 said:
Might have to make the factor even larger to cover more decimal places for double-precision floating point.
It's not as elegant as "a / b" but there is no helping it if "b" is zero or very darned close to zero.
Could go further in another application:
The "altsqrt()" isn't a very good example. Instead it should be able to come up with something like "2 + 3i" with "real" being 2 and "imag" being 3.
Code: (Select All)
dim as double a, b
a = 0
b = 0
print DivCheckZero(a, b)
end
function DivCheckZero# (a as double, b as double)
dim fret as double
if int(b * 1e+6) = 0 then
fret = 1
else
fret = a / b
end if
DivCheckZero# = fret
end function
Might have to make the factor even larger to cover more decimal places for double-precision floating point.
It's not as elegant as "a / b" but there is no helping it if "b" is zero or very darned close to zero.
Could go further in another application:
Code: (Select All)
function newtan# (degrees as double)
dim fret as double, intd as long
intd = int(degrees)
if intd = 90 or intd = 270 then
fret = 0
else
fret = tan(_d2r(degrees))
end if
newtan = fret
end function
function newsqrt# (num as double)
dim fret as double, intd as long
intd = int(num)
if intd < 0 then
fret = 0
else
fret = sqr(num)
end if
newsqrt = fret
end function
'CHANGED: real, imag
sub altsqrt (num as double, real as double, imag as double)
dim fret as double, intd as long
intd = int(num)
if intd < 0 then
imag = sqr(num * (-1))
real = 0
else
real = sqr(num)
imag = 0
end if
end function
The "altsqrt()" isn't a very good example. Instead it should be able to come up with something like "2 + 3i" with "real" being 2 and "imag" being 3.