World: r3wp
[!REBOL3-OLD1]
older newer | first last |
Geomol 9-Nov-2009 [19550] | I'm studying Lua these days, and they just have one function, that do: a - floor (a / b) * b Simple to understand. |
BrianH 9-Nov-2009 [19551] | What would be the consequences of such a change? I remember you going on about IEEE754 predictability, and this would seem to reduce precision - all that rounding... |
Geomol 9-Nov-2009 [19552] | I saw that implementation before I read about modulus on wikipedia and wolfram. |
BrianH 9-Nov-2009 [19553] | I would keep MODULO (maybe make it native) and let MOD be defined as an operator that redirects to it. |
Ladislav 9-Nov-2009 [19554] | operator? - do you mean infix? |
BrianH 9-Nov-2009 [19555] | Yes. It is intended that R3 op! functions be allowed to be defined on other types of functions than action! type. Even user-defined. |
Ladislav 9-Nov-2009 [19556] | So, Geomol, what is the result of a - floor (a / b) * b, if a = 0.3 and b = 0.1? |
Geomol 9-Nov-2009 [19557] | It might be a good idea to split the problem between integer and decimal behaviour. In the case of integer, there should be one way to do it. Today we have two different outcome: >> -8 // 3 == -2 >> mod -8 3 == 1 (MODULO give same result as MOD.) |
BrianH 9-Nov-2009 [19558] | See, that is what I was talking about: Different behavior with negative numbers. |
Geomol 9-Nov-2009 [19559] | Ladislav, the result is 0.1, and we know why. The programmer should know too and find some way to figure out, that 0.1 almost divide up in 0.3. One way is to divide 0.3 by 0.1 and see if the result is close to an integer. |
Ladislav 9-Nov-2009 [19560] | the result 0.1 is OK with me, but not with Gregg, neither with Carl, AFAIK |
BrianH 9-Nov-2009 [19561] | Modulus isn't defined for negative numbers, so different programming langages behave differently in that case. Some behave like //, some like MOD, some (correctly, but not usefully) error out. |
Geomol 9-Nov-2009 [19562] | as a side note, when would I ever use a modulus function with decimals? Maybe in special cases, where I need to write a special ROUND function myself or something? What is this use for else? |
BrianH 9-Nov-2009 [19563] | Proportional coordinates. |
Ladislav 9-Nov-2009 [19564] | as I said, I was asked to make MOD available; and to even add the MODULO function, since Gregg felt, that they were useful on their own. YMMV |
Geomol 9-Nov-2009 [19565x2] | *used* for |
Ladislav, I think, you and I agree much about many of these things. It's too bad, things get more complicated than necessary, because such functions become part of the language. | |
BrianH 9-Nov-2009 [19567] | The difference in the handling of negative numbers is sufficient justification for me. The rounding difference is just a bonus. |
Geomol 9-Nov-2009 [19568] | Brian, what do you mean with proportional coordinates and the use of modulus? |
Ladislav 9-Nov-2009 [19569x3] | regarding the "decimal arithmetic made easy" - this is not just the case of MODULO, it is also related to comparison, like EQUAL?, etc., I think, that it is Carl's design decision |
When we are at it, >> mold/all remainder 0.3 0.1 == "0.099999999999999978" , i.e. remainder 0.3 0.1 astually isn't 0.1, otherwise it would be really wrong! | |
excuse my typo above "actually" | |
Geomol 9-Nov-2009 [19572] | Would all those problems be solved, if the decimal! datatype actually was the money! datatype, and if we then had a real! datatype, that did it a fast way and giving results as we see in C and other languages? |
BrianH 9-Nov-2009 [19573] | As a practical example, if you are doing device-independent rendering you work in proportions (floating point ratios) and then convert to exact values (integer coordinates) on final rendering to the real device. Video games do this all the time - that is why GPUs need floating point hardware. Same with sub-pixel rendering. If you are working in proportions, your modulus functions will need to handle them. And modulus could be used for bounding box calculations on textured surfaces too. In both those cases, the programmer will probably know enough about accumulated error to want to control it themselves. The non-rounding behavior of // would be a benefit to them then, so rounding can be minimized. |
Geomol 9-Nov-2009 [19574] | I feel, much confusion come from having a decimal! datatype, that isn't really that, decimal. |
Ladislav 9-Nov-2009 [19575x2] | There are two reasons, why it it not feasible, IMO: 1) decimal! was used for IEEE754 as "the most common floating point datatype" 2) money! is not as "common", because it is slower, so maybe this should not change |
Otherwise, I am pretty sure, that the name "decimal!" was unfortunate! | |
BrianH 9-Nov-2009 [19577] | Also, think of the syntax. We have a sigil to denote the current money! type, which *was* added for financial calculations. If that type was the default, what would the floating-point sigil be? |
Ladislav 9-Nov-2009 [19578] | ...but, I guess, that Carl still thinks, that the majority of users may be formed by the people, for whom the name "64-bit binary floating point number" sounds like insult |
BrianH 9-Nov-2009 [19579] | I agree that float! would have been a better name than decimal! (not real! because they aren't). Too late now. |
Ladislav 9-Nov-2009 [19580] | real! is not that bad either, actually, they are (subset of) real numbers, with "just a bit twiddled" arithmetic |
BrianH 9-Nov-2009 [19581] | That "subset of" is the kicker. Integers are also a subset of real numbers. |
Ladislav 9-Nov-2009 [19582x2] | anyway, money! are implemented to have floating (really decimal in that case) point too |
yes, but (Rebol) integers are subset of integers too | |
Geomol 9-Nov-2009 [19584] | Brian, regarding graphics, wouldn't it be normal to convert the floats to integers before doing the modulus calculation? I may be wrong, but I'm not sure, I would need float modulus in such application. |
Ladislav 9-Nov-2009 [19585] | so, integer! datatype comprises some integer numbers, therefore the real! datatype could comprise some real number IMO |
Geomol 9-Nov-2009 [19586] | In Python, they call them reals. In Lua, you just have numbers. Integers and floats are the same internally as far as I can see. |
Ladislav 9-Nov-2009 [19587] | Reals surely is a much more appropriate name, than decimals |
Geomol 9-Nov-2009 [19588] | Thanks! :) I think the same. |
Ladislav 9-Nov-2009 [19589] | ...but I bet, that I and Geomol would be OK with IEEE-754! or a similarly "ugly" name, which may really scare some people |
BrianH 9-Nov-2009 [19590] | I still think float! is the most appropriate, due to that significant "subset of" thing. |
Ladislav 9-Nov-2009 [19591] | but, if you want be that precise, you cannot use the integer! name either |
Geomol 9-Nov-2009 [19592] | make IEEE-754! exp 1 oh no! :) |
Henrik 9-Nov-2009 [19593] | I agree on real! |
Geomol 9-Nov-2009 [19594] | A problem with "float" might be, that many will think 32-bit right away. And we have 64 bits to play with. |
BrianH 9-Nov-2009 [19595] | Geomol, it wouldn't be normal to convert to integers first if you are trying to manage rounding and the specific integer values are only an end-device approximation of real valued proportions and coordinates. In other cases, converting to integers would be appropriate. It varies. |
Ladislav 9-Nov-2009 [19596] | nevertheless, I guess, now it is not real to require real! as the real name :-D |
BrianH 9-Nov-2009 [19597] | A 64bit float is still a float. There are 128bit IEEE754 floats too (and perhaps 256bit, I don't know). |
Geomol 9-Nov-2009 [19598] | :) |
BrianH 9-Nov-2009 [19599] | No 256bit yet - it will come soon, I'm sure :) |
older newer | first last |