[Oberon] Rounding LONGREAL to LONGINT

Stefan Salewski Salewski at PHYSnet.Uni-Hamburg.de
Mon Sep 23 21:22:47 CEST 2002


Hello,

when rounding Reals to Integers we have at least four ways:
1. rounding to -Infinite (floor() in C)
2. roundind to +Infinite (ceil() in C)
3. rounding to nearest
4. rounding to zero

ENTIER(x) will provide rounding to -Infinite,
ENTIER(x+0.5D0) should provide rounding to nearest,
-ENTIER(-x) should provide rounding to +Infinite.

IF x>0 THEN RETURN ENTIER(x) ELSE RETURN -ENTIER(-x) END;
should provide rounding to zero.

Is there a better (faster) solution.
Sometimes I use x:=ENTIER(x+0.5D0).
I guess this is not very fast.

In http://www.oberon.ethz.ch/native/WebAlpha.html I read:

> Reals.Mod - Default rounding mode is now towards negative      
> infinity (like ENTIER). This allows ENTIER to be compiled much 
> more efficiently, because it does not need to set the rounding 
> mode. If you set another rounding mode with Reals.SetFCR, be   
> aware that ENTIER will also use this rounding mode! 

I do not fully understand this. Which parameters does 
Reals.SetFCR() need, which other functions exect ENTIER() does 
Reals.SetFCR() modify.

Best regards

  Stefan Salewski



More information about the Oberon mailing list