0

In Eiffel, the class DOUBLE_MATH defines trigonometric functions. When I see the interface of this class as shown here, it says

cosine (v: REAL_64): REAL_64 -- Trigonometric cosine of radian `v' approximated -- in the range [-pi/4, +pi/4]

and

sine (v: REAL_64): REAL_64 -- Trigonometric sine of radian `v' approximated -- in range [-pi/4, +pi/4]

and

tangent (v: REAL_64): REAL_64 -- Trigonometric tangent of radian `v' approximated -- in range [-pi/4, +pi/4]

It seems to claim that the trigonometric functions will only work in the domain [-pi/4,+pi/4]. However, when I tried using them for other values, they seemed to work.

I am worried that it might occasionally fail, or that the success I saw is in fact a form of undefined behavior that cannot be relied upon.

Is it safe to use the functions outside the given domain? If so, why is this domain specified? If not, why is it made such that the functions work only in this domain?

GoodDeeds
  • 7,956
  • 5
  • 34
  • 61
  • Note that the documentation of the arcus functions is simply wrong, the arguments are not in radians but just numbers, and the given range is not the domain="range of arguments" as with the other functions but the range (of values) of the function. And even that fails for the `arc_tangent`. – Lutz Lehmann Nov 06 '16 at 11:42
  • @LutzL Oh yes, I had not noticed that. So are you saying that they are not reliable? – GoodDeeds Nov 06 '16 at 11:49
  • I think you can use the functions without restriction. However, guarantees on the accuracy only apply for the small arguments. – Lutz Lehmann Nov 06 '16 at 12:12

1 Answers1

2

The functions are implemented as wrappers of the corresponding C functions from math.h. Because Eiffel can be compiled for virtually any platform with a C compiler, the comment makes sure to restrict the domain to most restrictive domains of C compiler implementations. Also, some CPUs provide direct support for trigonometric functions, but their precision goes down if the input value is beyond a given range.

To summarize, you need to check the manual of the C compiler for the platforms you are going to use for the specific ranges of trigonometric functions, or, alternatively, make sure the input value is in the range as specified in the comment.

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35