Here is a set of experimental classes for controlling floating point
output format. The ideas are: - 1) we can extend these formatting capabilities without creating a bunch of new messages combinations instead, we just have parameterized FloatPrinter object (+ subclasses), and use cascade of elementary messages The capabilities are right now limited to scientific, free format, fixed point and storeOn: format. But features are growable, and we could as well control localization, thousand separators, padding (total width, width left of fraction point, force + sign, etc...) - 2) The complex algorithm for printing accurately (Burger/Dybvig/Steele) has been split into private methods in order to be reusable by various format (fixed number of decimal places and fixed number of significand digits) I choosed to store above algorithm internal states in inst var in order to avoid explosion of meaningless parameters... This turns the functional implementation into a stateful implementation, but encapsulated in a class and private messages... It's a bit the same design choice as SqNumberParser. Having more comments is also a benefit (it's still preferable to read the paper though) The good news is that, despite parametrization and FloatPrinter instantiation, slow down is typically limited to 3% (we can optimize the default case eventually)... Comments, extensions and alternate design are welcome. Nicolas Experimental.st (21K) Download Attachment |
Take a look at the capabilities of the mpfr library. In the long
run, it might be good to be able to switch between the boxed float
primitive of squeak/pharo, and the extended capabilities of the
external lib: http://www.mpfr.org/ and the capabilities of mpfr
might be a good guideline for what an extended floating point class
should be able to do.
Lawson On 5/22/12 3:53 PM, Nicolas Cellier wrote: Here is a set of experimental classes for controlling floating point output format. The ideas are: - 1) we can extend these formatting capabilities without creating a bunch of new messages combinations instead, we just have parameterized FloatPrinter object (+ subclasses), and use cascade of elementary messages The capabilities are right now limited to scientific, free format, fixed point and storeOn: format. But features are growable, and we could as well control localization, thousand separators, padding (total width, width left of fraction point, force + sign, etc...) - 2) The complex algorithm for printing accurately (Burger/Dybvig/Steele) has been split into private methods in order to be reusable by various format (fixed number of decimal places and fixed number of significand digits) I choosed to store above algorithm internal states in inst var in order to avoid explosion of meaningless parameters... This turns the functional implementation into a stateful implementation, but encapsulated in a class and private messages... It's a bit the same design choice as SqNumberParser. Having more comments is also a benefit (it's still preferable to read the paper though) The good news is that, despite parametrization and FloatPrinter instantiation, slow down is typically limited to 3% (we can optimize the default case eventually)... Comments, extensions and alternate design are welcome. Nicolas -- Squeak from the very start (introduction to Squeak and Pharo Smalltalk for the (almost) complete and compleate beginner). https://www.youtube.com/playlist?list=PL6601A198DF14788D&feature=view_all |
In reply to this post by Nicolas Cellier
On Tue, May 22, 2012 at 3:53 PM, Nicolas Cellier
<[hidden email]> wrote: > Comments, extensions and alternate design are welcome. I like the design a lot. Recently I've had occasion to implement a couple of alternate integer printing implementations, and I found that a separate printer object works nicely. It would also be handy for non-invasive printing in the dev tools. Colin |
In reply to this post by LawsonEnglish
2012/5/23 Lawson English <[hidden email]>:
> Take a look at the capabilities of the mpfr library. In the long run, it > might be good to be able to switch between the boxed float primitive of > squeak/pharo, and the extended capabilities of the external lib: > http://www.mpfr.org/ and the capabilities of mpfr might be a good guideline > for what an extended floating point class should be able to do. > > Lawson > > http://www.mpfr.org/mpfr-current/mpfr.html#Formatted-Output-Functions tells mpfr provides kind of printf. That's the purpose of FloatPrinter experiments. Nicolas > > > > On 5/22/12 3:53 PM, Nicolas Cellier wrote: > > Here is a set of experimental classes for controlling floating point > output format. > The ideas are: > - 1) we can extend these formatting capabilities without creating a > bunch of new messages combinations > instead, we just have parameterized FloatPrinter object (+ > subclasses), and use cascade of elementary messages > The capabilities are right now limited to scientific, free > format, fixed point and storeOn: format. > But features are growable, and we could as well control > localization, thousand separators, padding (total width, width left of > fraction point, force + sign, etc...) > - 2) The complex algorithm for printing accurately > (Burger/Dybvig/Steele) has been split into private methods in order to > be reusable by various format (fixed number of decimal places and > fixed number of significand digits) > I choosed to store above algorithm internal states in inst var > in order to avoid explosion of meaningless parameters... > This turns the functional implementation into a stateful > implementation, but encapsulated in a class and private messages... > It's a bit the same design choice as SqNumberParser. > Having more comments is also a benefit (it's still preferable to > read the paper though) > > The good news is that, despite parametrization and FloatPrinter > instantiation, slow down is typically limited to 3% (we can optimize > the default case eventually)... > > Comments, extensions and alternate design are welcome. > > Nicolas > > > > > > -- > Squeak from the very start (introduction to Squeak and Pharo Smalltalk for > the (almost) complete and compleate beginner). > https://www.youtube.com/playlist?list=PL6601A198DF14788D&feature=view_all > > > > |
Free forum by Nabble | Edit this page |