1. Missing abs() in Euphoria?

Hi all,
Unless I overlooked it, it seems that Euphoria doesn't have a "abs()"
function to get the absolute value of a number... Of course it is very easy
to implement, but you should expect this to be a standard function in any
language..
Kind regards
Eddy

new topic     » topic index » view message » categorize

2. Re: Missing abs() in Euphoria?

Hi Eddy,

Yes, you are correct, there is no abs() function.

There has been considerable discussion over this on the list in the past.
The last mention I heard of it was at:

&H=0&O=D&T=1&m=20974

and quoted the function:

>The 'sequence-magic' abs() function is:
>
>function abs(object x)
>    -- The bit in the outer brackets is normally in the function "sgn()"
>    return x * ( (x>0)-(x<0) )
>end function

Ray Smith


----- Original Message -----
From: Eddy Van Esch <raimundo4u at YAHOO.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Tuesday, January 09, 2001 8:34 PM
Subject: Missing abs() in Euphoria?


> Hi all,
> Unless I overlooked it, it seems that Euphoria doesn't have a "abs()"
> function to get the absolute value of a number... Of course it is very
easy
> to implement, but you should expect this to be a standard function in any
> language..
> Kind regards
> Eddy

new topic     » goto parent     » topic index » view message » categorize

3. Re: Missing abs() in Euphoria?

Ray,

Carl's abs function is quite elegant, but the one below, proposed by
Pete, is generally faster. jiri

function abs(object x)
object temp
    if atom(x) then
        if x<0 then return -x else return x end if
    end if
    for i=1 to length(x) do
        temp = x[i]
        if atom(temp) then
            if temp<0 then x[i]=-temp end if
        else
            x[i]=abs(temp)
        end if
    end for
    return x
end function

----- Original Message -----
From: "Ray & Debbie Smith" <smithr at IX.NET.AU>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Wednesday, January 10, 2001 2:47 AM
Subject: Re: Missing abs() in Euphoria?


> Hi Eddy,
>
> Yes, you are correct, there is no abs() function.
>
> There has been considerable discussion over this on the list in the
past.
> The last mention I heard of it was at:
>
>
77&D=1
> &H=0&O=D&T=1&m=20974
>
> and quoted the function:
>
> >The 'sequence-magic' abs() function is:
> >
> >function abs(object x)
> >    -- The bit in the outer brackets is normally in the function
"sgn()"
> >    return x * ( (x>0)-(x<0) )
> >end function
>
> Ray Smith
>
>
> ----- Original Message -----
> From: Eddy Van Esch <raimundo4u at YAHOO.COM>
> To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
> Sent: Tuesday, January 09, 2001 8:34 PM
> Subject: Missing abs() in Euphoria?
>
>
> > Hi all,
> > Unless I overlooked it, it seems that Euphoria doesn't have a
"abs()"
> > function to get the absolute value of a number... Of course it is
very
> easy
> > to implement, but you should expect this to be a standard function
in any
> > language..
> > Kind regards
> > Eddy
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu