Re: something like 'abs()' ???

new topic     » goto parent     » topic index » view thread      » older message » newer message

eel picton wrote:
> 
> er... me again...
> 
> i cant seem to find the equivalent of an 'abs' or 'absolute' function as found
> in 'commodore
> 64' basic etc...
> 
> it is a function that returns the positive value of a number regardless of
> whether
> the original number is positive or negative
> 
> i have got around this by taking the square root of the square of the
> number...
> 
> but is there a simpler way anyone knows of? (maybe i'm having another
> brain-cell free
> day)

The EuForum archives are a good place to look up such things. One way:

function abs(integer x)
    return x * ((x>0) - (x<0))
end function

Regards,
Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu