[exslt] atan2 template
by Mike French other posts by this author
Mar 7 2007 7:50AM messages near this date
[exslt] need help in xslt...
|
Re: [exslt] atan2 template
& XSLT
Here's an inline XSLT template implementation of atan2.
It's accurate to +-0.005 radian, or +-0.3 degrees.
See the reference for more details.
Mik
<xsl:template name="atan2">
<xsl:param name="y"/>
<xsl:param name="x"/>
<!--
http://lists.apple.com/archives/PerfOptimization-dev/2005/Jan/msg00051.html
-->
<!--
#define PI_FLOAT 3.14159265f
#define PIBY2_FLOAT 1.5707963f
// |error| < 0.005 rad
// |error| < 0.3 deg
float fast_atan2f( float y, float x )
{
if ( x == 0.0f )
{
if ( y > 0.0f ) return PIBY2_FLOAT;
if ( y == 0.0f ) return 0.0f;
return -PIBY2_FLOAT;
}
float atan;
float z = y/x;
if ( fabsf( z ) < 1.0f )
{
atan = z/(1.0f + 0.28f*z*z);
if ( x < 0.0f )
{
if ( y < 0.0f ) return atan - PI_FLOAT;
return atan + PI_FLOAT;
}
}
else
{
atan = PIBY2_FLOAT - z/(z*z + 0.28f);
if ( y < 0.0f ) return atan - PI_FLOAT;
}
return atan;
}
-->
<xsl:variable name="PI" select="number(3.1415926535897)"/>
<xsl:variable name="PIBY2" select="$PI div 2.0"/>
<xsl:choose>
<xsl:when test="$x = 0.0">
<xsl:choose>
<xsl:when test="($y > 0.0)">
<xsl:value-of select="$PIBY2"/>
</xsl:when>
<xsl:when test="($y < 0.0)">
<xsl:value-of select="-$PIBY2"/>
</xsl:when>
<xsl:otherwise>
<!-- Error: Degenerate x == y == 0.0 -->
<xsl:value-of select="number(NaN)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="z" select="$y div $x"/>
<xsl:variable name="absZ">
<!-- inline abs function -->
<xsl:choose>
<xsl:when test="$z < 0.0">
<xsl:value-of select="- number($z)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($z)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="($absZ < 1.0)">
<xsl:variable name="f1Z" select="$z div (1.0 + 0.28*$z*$z)"/>
<xsl:choose>
<xsl:when test="($x < 0.0) and ($y < 0.0)">
<xsl:value-of select="$f1Z - $PI"/>
</xsl:when>
<xsl:when test="($x < 0.0)">
<xsl:value-of select="$f1Z + $PI"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$f1Z"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="f2Z" select="$PIBY2 - ($z div ($z*$z +
0.28))"/>
<xsl:choose>
<xsl:when test="($y < 0.0)">
<xsl:value-of select="$f2Z - $PI"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$f2Z"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Thales UK Ltd (Wells) DISCLAIMER: The information contained in this e-mail
is confidential. It may also be legally privileged. It is intended only for
the stated addressee(s) and access to it by any other person is
unauthorised. If you are not an addressee, you must not disclose, copy,
circulate or in any other way use or rely on the information contained in
this e-mail. Such unauthorised use may be unlawful. We may monitor all
e-mail communications through our networks. If you have received this e-mail
in error, please inform us immediately on +44 (0) 1749 672081 and delete it
and all copies from your system. We accept no responsibility for changes to
any e-mail which occur after it has been sent. Attachments to this e-mail
may contain software viruses which could damage your system. We therefore
recommend you virus-check all attachments before opening. A business of
Thales UK Ltd. Registered Office: 2 Dashwood Lang Road, The Bourne Business
Park, Addlestone, Weybridge, Surrey KT15 2NX Registered in England No.
868273
_______________________________________________
exslt mailing list
list@[...].org
http://www.exslt.org/list
Thread:
Mike French
Dimitre Novatchev
Dimitre Novatchev
James Fuller
James Fuller
Steve Derose
|