[Seaside-dev] Re: VW fun with Float printString

Lukas Renggli renggli at gmail.com
Fri Jun 5 06:52:02 UTC 2009


Hi Nicolas

For us, using platform code for priting number is out of question.
Every platform has a completely different API to print numbers and the
default #printString results in different froms:

  Squeak/GST: 3.141592653589793
  VisualWorks: 3.14159
  GemStone/S:  3.1415926535897931E+00

Although it would be desirable to make this more uniform, we do not
intend to endorse that. WANumberPrinter aims to provide a highly
configurable number printing only implemented using ANSI methods such
as #isNan, #isInfinite, #asFloat, #raisedTo:, #roundTo:,
#fractionPart, #abs, #rounded, #truncated, #quo:, #+, #-, #*.

There were two problems in our code:

- Floats have different precisions on different platforms. We solved
this problem by rewriting the tests so that they only use numbers with
a few significant digits. Like this it doesn't matter if the numbers
are internally represented as 32 or 64-bit floats. We assume that
people using floats are aware of the limitations on their particular
platform.

- We had bug in the code that caused the last digit of the fraction
part to be wrongly printed. Instead of truncating (what caused the
last digit to change in some cases) we round. This is also done in the
Squeak code of yours. This seems to be much more stable and produce
predictable results on different platforms. At least as long as the
numbers are "normal".

We will keep the #asExactFraction approach in mind. For now we don't
plan to depend on it, as it is not part of any standard and a correct
implementation seems to be tricky too.

Thanks again for your help.

Cheers,
Lukas

-- 
Lukas Renggli
http://www.lukas-renggli.ch


More information about the seaside-dev mailing list