Switch to full style
If you have any suggestions for improving the manual, this is the place for that. Please reports errors, typos, difficult to understand sections, missing information, etc. Also, any short code segments that better explain a topic are welcome.
Post a reply

ROUND p.57 v1.90.01

Mon Mar 13, 2017 11:45 am

The <mode_sexp> is an optional rounding mode. It is a one-or two-character mnemonic code that tells ROUND() what kind of rounding to do.

1. What is the default? It is explained later, too later as for me. You should say here something like "see below".


There are seven rounding modes:

"HE" Half-even -4.0 -4.0 -3.0 3.0 4.0 4.0
"HU" Half-up -4.0 -4.0 -3.0 3.0 4.0 4.0


2. Two ones actually do exactly the same, if I believe the table. Does not HE act differently of HU in some case?

Re: ROUND p.57 v1.90.01

Tue Mar 21, 2017 4:30 am

  1. There is no default rounding mode. The default behavior is different from all of the rounding modes. Perhaps I can make that clearer by putting "no mode" or "legacy mode" as a line in the table. My problem is that the modes are defined by Java, and the legacy mode is not defined by Java. The BASIC! programmer should not know or care what comes from Java.
  2. The table does not cover all possible cases. There isn't enough room. But there are enough cases that you know what would happen in all other cases.
    For example:
    • You can see that HE rounds -3.5 to -4, not -3. You can understand that it does that because -4 is even, and -3 is odd. Therefore HE would round -2.5 to -2.
    • However, HU rounds -3.5 to -4 because -4 is "up" (farther from 0) and -3 is "down" (closer to 0). By that understanding, you know that HU would round -2.5 to -3.
    While I am adding a row to the table, maybe I can see about squeezing in a column or two.

- Marc

Re: ROUND p.57 v1.90.01

Tue Mar 21, 2017 5:05 am

What do you think, Marc, of writing the following text?
The <mode_sexp> is an optional rounding mode. It is a one-or two-character mnemonic code that tells ROUND() what kind of rounding to do.
There is no default rounding mode, the default behavior (see it below) is different from all of the rounding modes. 

Re: ROUND p.57 v1.90.01

Thu Mar 23, 2017 5:29 pm

Thanks for the suggestion. I will use something like that in the new text, but it will change a little with the changes in the table.

I'm adding a row at the top. Under "Mode:" it says "(none)", and under "Meaning:" it says "Legacy", which will be explained in the text.
There is room to add two more columns, so right in the middle I'm adding "-2.5" and "2.5".
The new example columns show the difference between "HE" and "HU", and probably some other things.

I'll change the text to say there are "seven named modes and one unnamed Legacy mode, explained below", or something like that.

Finally, while working on that I discovered that the text describing Legacy mode is wrong. It said, "adds +0.5 and rounds down (toward zero)". That's not true. It adds +0.5 and rounds toward -∞ (floor function).

A note on BASIC! internals: the Legacy mode was not some whim of Paul's. It uses the standard Java rounding function for floating point numbers. The named modes, which are much newer, are defined by Java's BigDecimal class.

- Marc (somehow getting way behind in the forum again!)
Post a reply