Thread View: comp.lang.oberon
1 messages
1 total messages
Started by Frank Hrebabetzky - CERTI - CCE ...
Mon, 01 Apr 1996 02:45
Rounding Algorithms?
Author: Frank Hrebabetzky - CERTI - CCE ...
Date: Mon, 01 Apr 1996 02:45
Date: Mon, 01 Apr 1996 02:45
31 lines
1658 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads