Precision and CD's

David Carlisle davidc at nag.co.uk
Mon Jul 19 12:54:48 CEST 1999


> I'd just like some
> assurance that such a bigfloat CAN be converted to presentational 
> MathML by XSL.

not 100% there, but it is still monday morning (here) it would be
helpful to use some of the string indexing functions added to XSL in the
july 9th draft, but unfortunately I don't think there are any
implementations of that yet, so this is written using what's available
in the april draft.

It uses 123e3 notation for radix 10 floats and  explicitly does
mantissa times (radix ^ exponent) otherwise. Also has to special
case negative mantissa and apply a unary minus <mo>-</mo> as for some
reason the mathml REC says not to stick negative values inside <mn>
</mn>.

===============
openmath in

<test>

<OMOBJ>
<OMA>
  <OMS cd="bigfloat" name="bigfloat"/>
  <OMI> 123456789 </OMI>
  <OMI> 10 </OMI>
  <OMI> 5 </OMI>
</OMA>
</OMOBJ>

<OMOBJ>
<OMA>
  <OMS cd="bigfloat" name="bigfloat"/>
  <OMI> -123456789 </OMI>
  <OMI> 10 </OMI>
  <OMI> 5 </OMI>
</OMA>
</OMOBJ>

<OMOBJ>
<OMA>
  <OMS cd="bigfloat" name="bigfloat"/>
  <OMI> 123456789 </OMI>
  <OMI> xA </OMI>
  <OMI> -5 </OMI>
</OMA>
</OMOBJ>

<OMOBJ>
<OMA>
  <OMS cd="bigfloat" name="bigfloat"/>
  <OMI> 567890 </OMI>
  <OMI> 17 </OMI>
  <OMI> 10 </OMI>
</OMA>
</OMOBJ>

<OMOBJ>
<OMA>
  <OMS cd="bigfloat" name="bigfloat"/>
  <OMI> -567890 </OMI>
  <OMI> 17 </OMI>
  <OMI> 10 </OMI>
</OMA>
</OMOBJ>

</test>


===================

presentation mathml out

====================


<mn>123456789e5</mn>

<mrow><mo>-</mo><mn>123456789e5</mn></mrow>

<mn>123456789e-5</mn>

<mrow><mn>567890</mn><mo>X</mo><msup><mn>17</mn><mn>10</mn></msup></mrow>


<mrow><mo>-</mo><mrow><mn>567890</mn><mo>X</mo><msup><mn>17</mn><mn>10</mn></msup></mrow></mrow>


====================

XSL, for them that want it

========================




<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
  result-ns="">


<xsl:template match="OMA[OMS[position()=1 and @cd='bigfloat' and @name='bigfloat']]">
  <xsl:variable name="mantissa" expr="normalize(*[2])"/>
  <xsl:choose>
  <xsl:when test="starts-with($mantissa,'-')">
  <mrow><mo>-</mo>
   <xsl:call-template name="bigfloat">
    <xsl:param name="mantissa" expr="substring-after($mantissa,'-')"/>
   </xsl:call-template>
  </mrow>
  </xsl:when>
  <xsl:otherwise>
  <xsl:call-template name="bigfloat"/>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>


<xsl:template name="bigfloat">
   <xsl:param-variable name="mantissa" expr="normalize(*[2])"/>
   <xsl:param-variable name="radix" expr="normalize(*[position()=3 and from-self(OMI)])"/>
   <xsl:param-variable name="exponent" expr="normalize(*[4])"/>
   <xsl:choose>
   <xsl:when test="$radix='10' or $radix='xA'">
      <mn><xsl:value-of select="$mantissa"/>e<xsl:value-of select="$exponent"/></mn>
   </xsl:when>
   <xsl:otherwise>
   <mrow>
   <mn><xsl:value-of select="$mantissa"/></mn>
   <mo>X</mo>
   <msup>
     <mn><xsl:value-of select="$radix"/></mn>
     <mn><xsl:value-of select="$exponent"/></mn>
   </msup>
   </mrow>
   </xsl:otherwise>
   </xsl:choose>
</xsl:template>



</xsl:stylesheet>



More information about the Om mailing list