1. Re: ABS

Hello,
I haven't been keeping up on the ABS functions contest much but here's
one that is probably slow but simple:

  function abs(object x)
      return sqrt(x*x)
  end function

I don't think that sqrt() is very fast so it probably won't win any
awards but I think it's simpler (logically) than any I've seen thus far.
I have an example program that demonstrates how it works for atoms as
well as sequences.
here it is if anyone wants it:

--------------<abs.ex>------------------
object n
function abs(object x)
        return sqrt(x*x)
end function

n = repeat (0,20)
for i = 1 to length (n) do
        n [i] = rand(200) - 100
end for
print (1,n)
puts (1,"\n")
print (1, abs (n))
puts(1,"\n")
for i = 1 to 20 do
        n = rand (200) -100
        print (1,n)
        puts (1,"\t")
        print (1, abs (n))
        puts (1,"\n")
end for
----------------------------------------

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu