Re: Strange problem

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

Rett,

>Sometimes I am a little slow, but I do finally get there. In a case where
>the
>system truncates rather than rounds, the normal solution is to add .5
>except in this case where we are not sure that the conversion is always
>less than the original decimal number. Given the answer to that question is
>yes, then adding .5 solves the problem. Only a lot of very exacting testing
>or
>an answer from RDS will solve the question for sure.
>
>Everett L.(Rett) Williams
>rett at gvtc.com

It doesn't matter if the value is a tiny bit below or above the
desired number the following function will always round it to
the nearest integer... I think. This is untested so I may have
some syntax errors but I think the logic is sound. Please let
me know if it isn't. Please note also that my problem is now
solved, thanks to you and others.

function int_round (atom a)
  integer sign sign = 1
  if a < 0 then
    sign = -1
  end if
  return floor (a + .5 * sign)
end function

I suppose one could write a recursive version of this to
work with sequences.

later,

Lewis Townsend
keroltarr at hotmail.com
http://geocities.com/keroltarr/
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu