Partial trig functions

Does any programming language (including those embedded in statistical analysis packages) let you specify the domain of trig functions, or restrict them by default to a single cycle (eg 0-360 degrees)? I was reading this (please ignore the politics and point-scoring involved unless you enjoy that kind of thing) and wondered how common such errors were - I've certainly done similarly stupid things.

Another (better, since it would catch radians used as degrees, as well as being more general) solution would be physical units within the type system (although angles are dimensionless, so you'd need quite a pedantic system, I would guess).

((Unit) Tests pick up problems like this, of course).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Yes, Mathematica

Define functions with specified domains or solve equations with domain assumptions for the unknowns.

Other packages offer similar capabilities, but none as comprehensive to my knowledge.

thanks! (some of that page is

thanks! (some of that page is a bit worrying - it's kind of teaching people maths by talking to a computer, and the reason cos(x) = sin(x+pi/2) seems to be because it looks right and mathematica says so. eek. but it's pretty impressive anyway.)

Better math than the textbooks

Pedagogy assertions aside, mathematica says so can be more trustworthy than standard published reference works, with good reason.

Portal site.