FixedPoint storeOn: will store the rounded value, not the exact value. 0.5s1 squared storeOn: Transcript. Transcript cr; flush. When evaluated back precision is lost. Nicolas |
Created the following AR:
Thanks, Dave AR 51045 FixedPoint should implement #storeOn: Number>>storeOn: simply sends printOn:, which is inappropriate for FixedPoint since the number read back is not equivalent to the original. For example: | stream | stream := String new writeStream. 0.5s1 squared storeOn: stream. (Object readFromString: stream contents) asRational printString answer: '(3/10)' original: '(1/4)' They still print the same (0.3s), but they are now different. May not seem like much, but after all, 5% is 5%, and it adds up after a while... Perhaps the example above should store itself as '0.25s1' to preserve precision. nicolas cellier wrote: > FixedPoint storeOn: will store the rounded value, not the exact value. > > 0.5s1 squared storeOn: Transcript. > Transcript cr; flush. > > When evaluated back precision is lost. > > Nicolas > > |
Le Mardi 01 Août 2006 06:46, Dave Stevenson a écrit :
> > AR 51045 FixedPoint should implement #storeOn: > Thanks for creating the AR > Number>>storeOn: simply sends printOn:, which is inappropriate for > FixedPoint since the number read back is not equivalent to the original. > > For example: > | stream | > > stream := String new writeStream. > 0.5s1 squared storeOn: stream. > (Object readFromString: stream contents) asRational printString > > answer: '(3/10)' > original: '(1/4)' > > They still print the same (0.3s), but they are now different. May not > seem like much, but after all, 5% is 5%, and it adds up after a while... > > Perhaps the example above should store itself as '0.25s1' to preserve > precision. > That would be all right if you can make sure your fraction has only powers of 2 and 5 at denominator, what happens when you create a FixedPoint and deal only with (* = -). Then there is an exact decimal representation (in a finite number of digits, possibly many). But if you mix arithmetic with other numbers, especially Fraction, or use FixedPoint division, then you can no more have an exact representation in a finite number of decimals. try (1/3) * (0.5s1)... or (0.5s1) / (0.3s1) Either you store with some kind of message send (fraction asFixedPoint:...) Or you loose exactness at load/store operation (whatever the arbitrary number of digits over scale you decide). It depends on application side... Maybe second solution is sufficient for majority of financial apps, but not for a symbolic algebra framework. Maybe storeOn: message itself is limited and a little deprecated for a serious load/store implementation... Nicolas |
Something like this should suffice:
1/4s1 since this includes all the internal representation of a fixed point: numerator denominator scale I'll update the AR. Dave nicolas cellier wrote: > Le Mardi 01 Août 2006 06:46, Dave Stevenson a écrit : >> AR 51045 FixedPoint should implement #storeOn: >> > > Thanks for creating the AR > >> Number>>storeOn: simply sends printOn:, which is inappropriate for >> FixedPoint since the number read back is not equivalent to the original. >> >> For example: >> | stream | >> >> stream := String new writeStream. >> 0.5s1 squared storeOn: stream. >> (Object readFromString: stream contents) asRational printString >> >> answer: '(3/10)' >> original: '(1/4)' >> >> They still print the same (0.3s), but they are now different. May not >> seem like much, but after all, 5% is 5%, and it adds up after a while... >> >> Perhaps the example above should store itself as '0.25s1' to preserve >> precision. >> > > That would be all right if you can make sure your fraction has only powers of > 2 and 5 at denominator, what happens when you create a FixedPoint and deal > only with (* = -). Then there is an exact decimal representation (in a finite > number of digits, possibly many). > > But if you mix arithmetic with other numbers, especially Fraction, or use > FixedPoint division, then you can no more have an exact representation in a > finite number of decimals. > > try (1/3) * (0.5s1)... or (0.5s1) / (0.3s1) > Either you store with some kind of message send (fraction asFixedPoint:...) > Or you loose exactness at load/store operation (whatever the arbitrary number > of digits over scale you decide). > > It depends on application side... Maybe second solution is sufficient for > majority of financial apps, but not for a symbolic algebra framework. > > Maybe storeOn: message itself is limited and a little deprecated for a serious > load/store implementation... > > Nicolas > > |
Free forum by Nabble | Edit this page |