metaeducation / ren-c

Library for embedding a Rebol interpreter into C codebases
GNU Lesser General Public License v3.0
128 stars 27 forks source link

Arithmetic of MONEY! #862

Open giuliolunati opened 6 years ago

giuliolunati commented 6 years ago

Things IMO are wrong: $1 + 1 => $2 (should be error) $1 * $1 => $1 (should be error) $6 / $2 => $3 (should be 3) 6 / $2 => $3 (should be error) (But $6 / 2 => $3 is right)

hostilefork commented 6 years ago

I agree that it's weird. But @gchiu and I had once tried changing $6 / $2 => 2. This received some backlash from earl and was reverted.

In Carl's opinion $ was not really just about money, but it was a type to be used for "arbitrary precision math". From the comments here:

http://www.rebol.net/cgi-bin/r3blog.r?view=0201#comments

You should consider the $ just as a notation that means APM (arbitrary precision math). It is a lexical notation to separate it from decimal (FPM). We could have used some other notation, but the lexicon does not have many left.

If you read through those comments you can see what you think. In any case, the reason people don't want $6 / $2 to produce 3 is because of the loss of precision that converting to integer has.

giuliolunati commented 6 years ago

That means money type implements APM?

hostilefork commented 6 years ago

It's original code in Rebol (which Ladislav wrote, I believe), and the datatype is deceptively called deci:

https://github.com/metaeducation/ren-c/blob/2fe6342bf1894b630524641a4385fee4f0066fc6/src/core/f-deci.c#L30

Red does not appear to support MONEY! yet, so I don't know what their plan is. Especially if they're trying to have notations for cryptocurrency.

I've never used the MONEY! type. For what I'm interested in, I've been feeling like $1 and $2 etc. are more useful for parameter indexing. And I've felt that $true and $false are better than #[true] and #[false]. So I don't have a lot of opinions about it, other than it indicates the kind of thing I feel should be modular in the language so you can load the feature only if you want it.

giuliolunati commented 6 years ago

Wow, so MONEY! is a 26-decimal-precision number! Then we should change the name... Perhaps LONGDECIMAL! ?

giuliolunati commented 6 years ago

No... It allows only arithmetic, no other math functions :-/