23 May 2012 16:05
Re: Experimental classes for controlling Float printing format
Nicolas Cellier <nicolas.cellier.aka.nice <at> gmail.com>
2012-05-23 14:05:37 GMT
2012-05-23 14:05:37 GMT
2012/5/23 Lawson English <lenglish5 <at> cox.net>: > 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 > > > >
RSS Feed