Project

Profile

Help

adaptive serialize 0e0

Added by Air Quick almost 4 years ago

serialize(0e0, map {'method': 'adaptive'}) returns these different results. Are Saxon J and JS working correctly here?

$ cat serialize.xsl 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="#all">
  <xsl:output method="text"/>
  <xsl:template name="xsl:initial-template">
    <xsl:value-of select="serialize(0e0, map {'method': 'adaptive'})"/>
  </xsl:template>
</xsl:stylesheet>
$ java -jar saxon-he-10.3.jar -it -xsl:serialize.xsl
0.0e-1
$ npx xslt3 -it -xsl:serialize.xsl
npx: installed 6 in 8.657s
0
$ basex/bin/basex "serialize(0e0, map {'method': 'adaptive'})"
0.0e0

Replies (2)

RE: adaptive serialize 0e0 - Added by Michael Kay almost 4 years ago

The spec says:

An instance of xs:double is serialized by applying the function format-number(?, '0.0##########################e0') using the following default decimal format properties.

In Saxon 10.3 format-number(0.0e0, '0.0##########################e0') outputs 0.0e-1 -- which seems rather strange!

The rules for format-number() say:

*The scaling factor is a non-negative integer used to determine the scaling of the mantissa in exponential notation. It is set to the number of ·decimal digit family· characters found in the integer part of the sub-picture.

If the minimum exponent size is non-zero, then the adjusted number is scaled to establish a mantissa and an integer exponent. The mantissa and exponent are chosen such that all the following conditions are true: 1 The primitive type of the mantissa is the same as the primitive type of the adjusted number (integer, decimal, float, or double). 2 The mantissa multiplied by ten to the power of the exponent is equal to the adjusted number. 3 The mantissa is less than 10^N, and at least 10^(N-1), where N is the scaling factor.

It seems to me that when the adjusted number is 0.0, there is no scaling that will satisfy condition 3, so the rules are flawed.

    (1-2/2)

    Please register to reply