🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.oberon
Article #1244

Rounding Algorithms?

#1244
From: Frank Hrebabetzky - CERTI - CCE ...
Date: Mon, 01 Apr 1996 02:45
31 lines
1658 bytes
Some time ago I wrote some procedures for rounding real numbers:

PROCEDURE round (x:LONGREAL; n:INTEGER): LONGREAL;
(* Round x to n digits. *)

PROCEDURE roundp (x:LONGREAL; n:INTEGER): LONGREAL;
(* Round x to n digits behind the decimal point. *)

PROCEDURE RealToStr (x:LONGREAL; n:INTEGER; VAR s:ARRAY OF CHAR);
(* Convert x to s, rounding to a total of n characters.
   n>0: floating point, else exponential.
*)

I am not so happy with my solutions, because I use logarithms and 
exponential functions to generate power-of-10-factors for left- and 
right-shifting and ENTIER for truncation. Sometimes arithmetic errors in 
those functions give me a result of 9.99 when I want to round 10. 

Does anybody know procedures or algorithms or references about that topic? 


Thanks in advance.

-----------------------------------------------------------
Fundacao CERTI			Tel.:	+55 / 48 / 234-3000
Dr. Frank Hrebabetzky		Fax:	+55 / 48 / 234-1514
Campus da UFSC, CP 5053		email:	fh@mbox1.ufsc.br
Florianopolis, SC		        fh@certi.ufsc.br
88040-970
Brasil
Technical Details
Message-ID: <Pine.3.87.9603312356.A16762-0100000@mbox1.ufsc.br>
Path: arc1-ca.pugleaf.net!inf.ethz.ch!oberon-news@inf.ethz.ch

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!inf.ethz.ch!oberon-news@inf.ethz.ch
From: Frank Hrebabetzky - CERTI       - CCE 2319561 <fh@mbox1.ufsc.br>
Newsgroups: comp.lang.oberon
Subject: Rounding Algorithms?
Date: 1 Apr 1996 04:45:01 +0200
Organization: Dept. Informatik, Swiss Federal Institute of Technology
Sender: server@inf.ethz.ch
Distribution: world
Message-ID: <Pine.3.87.9603312356.A16762-0100000@mbox1.ufsc.br>
Reply-To: oberon-news@inf.ethz.ch
NNTP-Posting-Host: neptune.inf.ethz.ch
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Originator: oberon-news@inf.ethz.ch