Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with NAN
#5
Must do things this way instead as DSMan195276 said:

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.
Reply


Messages In This Thread
Working with NAN - by Dimster - 09-08-2023, 03:45 PM
RE: Working with NAN - by DSMan195276 - 09-08-2023, 03:57 PM
RE: Working with NAN - by mnrvovrfc - 09-08-2023, 04:03 PM
RE: Working with NAN - by Dimster - 09-08-2023, 06:06 PM
RE: Working with NAN - by mnrvovrfc - 09-08-2023, 06:22 PM
RE: Working with NAN - by DSMan195276 - 09-08-2023, 07:43 PM
RE: Working with NAN - by Dimster - 09-09-2023, 01:42 PM
RE: Working with NAN - by DSMan195276 - 09-09-2023, 02:31 PM
RE: Working with NAN - by Dimster - 09-09-2023, 03:48 PM
RE: Working with NAN - by SMcNeill - 09-09-2023, 05:03 PM
RE: Working with NAN - by Dimster - 09-09-2023, 06:48 PM
RE: Working with NAN - by SMcNeill - 09-09-2023, 07:11 PM
RE: Working with NAN - by SMcNeill - 09-09-2023, 07:26 PM
RE: Working with NAN - by SMcNeill - 09-09-2023, 08:15 PM
RE: Working with NAN - by grymmjack - 09-10-2023, 12:24 AM
RE: Working with NAN - by eoredson - 09-15-2023, 03:03 AM



Users browsing this thread: 7 Guest(s)