[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Calculate mantissa and exponent?

Subject: Re: Calculate mantissa and exponent?
From: David_Marston@xxxxxxxxx
Date: Fri, 10 Aug 2001 15:10:57 -0400
mantissa and exponent
Edmund Mitchell writes:
>I have to calculate a numbers' mantissa and exponent.
>So if I have 123456, it should be normalized as 1,23456e+5.
>Unfortunately, I have to use only pure xsl, no extension functions
>or scripts are allowed.

I've been pondering this one. This could be tackled as a string issue
rather than a numeric one, which might be more efficient. To begin,
if $abs-input is the absolute value of the input, then
string-length(floor($abs-input))
is the number of decimal places in the whole part, and your exponent
is one less than that number. It's also the amount that you would
want to shift the decimal-separator. The various string functions
would let you pull apart the number and build the new string with no
div operations at all and no recursion.

If you want to do exactly one div or multiply to shift the
decimal-separator, you could use recursion to calculate the Nth
power of ten, or a string operation. For positive values of N,
number(concat('1',substring('000000000000000',1,$N)))
is ten to the Nth power. (Expand that string of zeroes if you know
that your XSLT processor can handle more.)

If you knew that your input numbers were limited to a few orders of
magnitude in a contiguous range, you could set up an efficient
xsl:choose by depending on the fact that the first matching xsl:when
sub-element is the only one executed. Each xsl:when would perform the
exact div for a particular number of decimal places (e.g., the
four-place shift for 10000 to 99999) and concat on the exponent.

Keep in mind that format-number alone won't do the necessary shift of
the decimal-separator. You need to do your own multiply/divide or the
string equivalent.

Details are left as an exercise for the reader, just in case this is
somebody's homework assignment.    :)
.................David Marston


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.