Hi Nocolas,<br><br>Thanks for the review. I have not actually used this for arithmetic yet, I added that in a couple of hours before publishing this. Previously this has been used to represent the decimal values that I needed to use to load into a database using a fixed length representation. This need influenced my design quite a bit. However, without arithmetic, it isn't very useful for many other people (or myself going forward).
<br><br>As to your points;<br><br><div><span class="gmail_quote"><br></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">(-53/10 asFixedDecimal: 2) fractionPart.
</blockquote><div><br>Right. I did not finish adding in all of the protocol that should be added. I will continue to do this over the next few days as I have time. For now, this works:<br><br>(-53/10 asFixedDecimal: 2) fractionPart. -
0.30<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">- why maintaining so many forms in parallel ?<br> Not bug-proof, you happen to update one form not the other...
<br> sign is not handled in part1 nor part2</blockquote><div><br>This is a result of what I was originally using it for, which works pretty well (until I introduce bugs, that is). Keeping the various different forms there does make certain transformations much easier to handle. However, I might take a look at other ways to handle this. (Also, this repository is open, is if anyone wants to add a different representation, they are free to do so).
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">- negated should create a new instance<br> rather than modifying the number in place
</blockquote><div><br>Yes, that was a bad choice. It is now making a new instance. <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
- FixedDecimals does not implement hash,<br> therefore cannot be stored in a Dictionary.</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Particularly, cannot be stored in a workspace variable.<br> I suggest hash ^self asFraction hash</blockquote><div><br>This is now fixed, as you suggested. Although I may tweak this (is there a good hash tester available for Squeak?)
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">- likewise, implement all subclassResponsibility</blockquote><div><br>Right. I'm working on that...
</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> ( 5/3) * (5/3 asFixedDecimal: 2).<br> ( 2.0s1) * (5/3 asFixedDecimal: 2).
<br> (5/3 asFixedDecimal: 2) reciprocal.</blockquote><div><br>Fixed. See below.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
- coercion depends on receiver:<br> | a b |<br> a := (53/10 asFixedDecimal: 2).<br> b := 5.3.<br> { (a+b) class.<br> (b+a) class. } "is {FixedDecimal . Float}"</blockquote><div>
<br>Hmmm. Yes. I think I want all arithmetic with FixedDecimals to return a FixedDecimal. Looking as ScaledDecimals, I notice that what is returned is consistent with for a given other magnitude, but not always the same. Is there a rational behind which type of number is returned? Is it spelled out in ANSI?
<br>(Also, while checking this, I noticed that .333 does not give you 0.333 but rather 333. I wonder if I've coded in a bug like that somewhere else? If the . is the first part of the method or workspace, it just quitely eats it.)
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">- maybe add another rounding mode in arithmetic (to nearest even...)</blockquote>
<div><br>I might add something like that as time permits. Do you have a use for it? <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
- create a specific notation for transparent read/write, like 5.30f<br> (requires some easy support in Number class>>readFrom: or NumberParser)</blockquote><div><br>Will do. <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
From algebraic point of view, the main concern is that some numbers<br>might not have any reciprocal...<br>Unless the reciprocal is a Fraction, and arithmetic op coerce to Fraction...<br>But, eh, this is just the case of Float:
<br>| f |<br>f := (8872240531573379/9007199254740992) asFloat.<br>f * f reciprocal - 1</blockquote><div><br>Well, this particular number DOES have a reciprocal in FixedDecimals which just happens to be a FixedDecimal. You just have to specify the scale right:
<br>fd _ (8872240531573379/9007199254740992) asFixedDecimal: 53 <br>rfd _ fd reciprocal<br>rfd reciprocal <br>fd * rfd - 1 = 0.00000000000000000000000000000000000000000000000000000<br>That said, there might be some rational numbers that will not have a reciprocal, but I can't find them. For instance:
<br>fd _ (1/3) asFixedDecimal: 5 "= 0.33333"<br>rfd _ fd reciprocal "= 3.00003"<br>fd * rfd - 1 "0.00000"<br><br></div>Most of this is now out in SqueakSource. I'll do some more as time permits. (Also, all of these changes now have tests, too).
<br><br>Thanks,<br>Chris<br></div>