date!``/dayto -1? Maybe it should be avoided? Plus variant works imo, if the assumption is correct, that setting such value sets it to the day-of-month value. Well, if it overflows the recent month, it goes into the next one. But what about negative values?
>> today: now == 6-Aug-2017/10:00:41+02:00 >> today/day: 1 == 1 >> today == 1-Aug-2017/10:00:41+02:00 >> today/day: -1 == -1 >> today == 30-Jul-2017/10:00:41+02:00
dayto 1, does not increment the recent day, it just sets it to that value. But try with the
40for e.g. - it overflows to September ....
>> d: now == 6-Aug-2017/16:32:36+8:00 >> d/day: -1 == -1 >> d == 30-Jul-2017/16:32:36+8:00
>> d: 1-8-17 == 1-Aug-2017 >> d/day: 0 == 0 >> d == 31-Jul-2017 >> d: 1-8-17 == 1-Aug-2017 >> d/day: -1 == -1 >> d == 30-Jul-2017
>> now/date - now/date == -1 >> 6-aug-2017 - 6-aug-2017 == 0 >> 6-aug-2017 - now/date == 0 >> now/date - 6-aug-2017 == -1
@GiuseppeChillemi, no need to apologize, ever. Same goes for everyone else. Your English beats my Italian every day. :^) If I ask for clarification, it could be a technical matter as much as anything, wanting to make sure I understand the problem so I don't give bad advice.
The answer is easy.
Float! should never be used for decimal values where accuracy is important, because it can't represent all decimal values. See: https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems
This won't always be visible, but it's there:
>> 0.1 + 0.1 + 0.1 == 0.3 >> 0.1 + 0.1 + 0.1 * 10000000000000000 == 3000000000000001.0
When working with money values, rounding errors can add up. I worked with a guy, many years ago, who developed empirical solutions for it, which was pretty amazing. It worked in our domain, but I don't think was generalizable. The solution is to use BCD or some other representation that can accurately handle decimal values. That's the plan for
money! in Red, but could also be a general
decimal! type that money is built on. The issue then is what
1.0 means as a literal, float or decimal. Floats are faster, because of hardware support.
There are other interesting approaches as well, but that should be enough for now.
money!in R3 is https://en.wikipedia.org/wiki/Binary-coded_decimal
test2function, I have set
m: 1,why the print is
122after second recursion
m: "1" binds the word in the local context of the function to a string value whose initial content is "1". Assume that the "address" of the string is str-1234. 'm: 1' binds 'm' to str-1234.
m: append m "2" binds
m to the value returned by
append which is the value 'm' is bound to (i.e. str-1234) with "2" appended to it.
Next time, the function is called; 'm: "1"' still binds 'm' to str-1234 which now contains "12".