Re: is scientific notation allowed in numbers?

Apu Nahasapeemapetilon wrote:
> 
> In path data, is it OK to output floating point
> coordinates in scientific notation?

Yes.
 
> In other words, can I write
>    3.450000e-004
> instead of
>    0.000345

Yes, you can (although superfluous trailing and leading zeros should
ideally be omitted to minimise file size. Only use the precision that is
needed for the task). So in your example above, 3.45e-4 

> The specification should make it clear if this is
> allowed or not.

I agree. 

It is clear on close reading ;-) which means we should make it clearer
in the next draft, but I agree that all the exampkles currently use only
integer values and that section 10.3.1 should explicitly state that
floating point coordinates are allowed.

The grammar for path data shows that floating point is allowed:

   number:
         sign? integer-constant
         | sign? floating-point-constant

   floating-point-constant:
         fractional-constant exponent?
         | digit-sequence exponent

   fractional-constant:
         digit-sequence? "." digit-sequence
         | digit-sequence "."

   exponent:
        ( "e" | "E" ) sign? digit-sequence

   sign:
        "+" | "-"

   digit-sequence:
        digit
        | digit digit-sequence

  digit:
        "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"


> Ideally the SVG spec must explicitly allow numbers
> in scientific notation so that SVG viewers will be
> prepared to handle this.

Existing viewers do handle this, that I have seen. I have not tested
them exhaustively. But it would be most odd if an existing viewer, which
supported the current latest public draft, did not support the path
syntax exactly as specified.

If anyone finds an implementation which fails on floating point
coordinates, please mail the maintainer of that software and refer them
to this URL:

http://www.w3.org/1999/08/WD-SVG-19990812/paths.html#PathDataBNF

Anyone have good tools that take a BNF and write a checker for
conformance to that BNF? 

That would be a handy thing to hook up to an XML parser (a SAX parser
would be adequate for this, though a DOM implementation would also work)
and have it check all paths in an SVG file.

--
Chris

Received on Saturday, 13 November 1999 23:44:02 UTC