This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 5892 - [FO11] Requirement: trigonometric functions
Summary: [FO11] Requirement: trigonometric functions
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.0 (show other bugs)
Version: Recommendation
Hardware: PC Windows NT
: P2 enhancement
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-22 22:43 UTC by Michael Kay
Modified: 2009-10-12 22:33 UTC (History)
4 users (show)

See Also:


Attachments

Description Michael Kay 2008-07-22 22:43:20 UTC
I've been doing some work recently with geographic/spatial data sets and SVG. XSLT and XQuery are ideal for manipulating this kind of data but have one serious shortcoming - the lack of some basic functions needed for geometrical calculations.

I would therefore like to propose the addition of four functions: sqrt(), sin(), cos() and tan(), all defined with the signature X(xs:double?) -> xs:double?.

I don't think that providing these will be a major burden on implementors since they are so widely implemented in standard libraries and the specification is unproblematic.

I know this isn't on the requirements list but I think there's a real user need and the benefit is worth the effort.
Comment 1 Colin Adams 2008-07-29 08:20:23 UTC
I'd second this.

Presumably the arguments would be in radians for the trig. functions? 

Wouldn't it make sense to have inverse functions too?
Comment 2 Tim Mills 2008-11-12 13:08:34 UTC
We have implemented a bunch of maths functions (documented at http://www.xqsharp.com/xqsharp/functions.htm).

When we came to implement the sin/cos functions using the Microsoft .NET implementations, we were surprised by the behaviour on large inputs:

"For values of $arg outside the range from approximately -9223372036854775295 to approximately 9223372036854775295, the fn:cos function returns $arg unchanged."

as a result of the behaviour of Math.Sin documented at

http://msdn.microsoft.com/en-us/library/system.math.sin.aspx

which we presume is due to the behaviour of the C function documented at

http://msdn.microsoft.com/en-us/library/aa272931(VS.60).aspx

There is further information relating to the Java platform at

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html

and

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StrictMath.html

which offers two implementations (StrictMath.Sin and Math.Sin).

I mention this because it may need to be considered when deciding what results  might be considered as conformant for a particular function.
Comment 3 Deborah Pickett 2008-12-08 10:46:13 UTC
Equally as important as sin(x) and cos(x) is atan2(y,x).  Just as sin and cos are useful for converting polar coordinates to rectangular coordinates, atan2 is essential for converting rectangular coordinates to polar.

With atan2 and sqrt, computing other inverse trigonometric functions is easy, just as it is easy to compute tan given implementations for sin and cos.
Comment 4 Michael Kay 2008-12-08 11:04:43 UTC
Yes, I agree with comment #3
Comment 5 Jim Melton 2009-03-14 19:48:41 UTC
The WGs agreed in principle, at its F2F meeting during the week of 2009-03-23, to add a number of such functions. I'm marking this bug ACCEPTED, and it will be marked RESOLVED/FIXED when the details have been made more public (e.g., in a public Working Draft). 
Comment 6 Michael Kay 2009-10-12 22:33:03 UTC
Despite Jim's statement in comment #5, I am following the convention we have used for other bugs: it is Fixed/Resolved when a decision is made, and Closed when the editor's draft has been updated. I am therefore marking this fixed and closed.