11

cppreference includes the following description about the return value of std::sin:

The result may have little or no significance if the magnitude of arg is large (until C++11)

I've tried to find information about this in the current C++ standard, but I've found nothing (maybe I missed it?). What has exactly been changed in C++11 this regard about std::sin?

geza
  • 28,403
  • 6
  • 61
  • 135
  • There is no `std::sin` in C, so I removed that part. Don't confuse the two languages. – Rakete1111 Oct 12 '17 at 15:45
  • 2
    @Rakete1111: there are parts of the C++ standard which refer to the C standard, aren't they? (at least I have some memory that I've seen this - maybe I remember wrongly...) – geza Oct 12 '17 at 15:47
  • 1
    Well yeah, but it is still the C++ standard, not the C one. [library.c](http://eel.is/c++draft/library.c) – Rakete1111 Oct 12 '17 at 15:50
  • 2
    `sin` can be calculated with the argument `mod 2 pi`, but for a large `double` number the least significant numbers are not significant. So `sin(5e100)` will probably not return the correct result: https://ideone.com/LORAwb – mch Oct 12 '17 at 15:50
  • 2
    It is just an inevitable side-effect of sin() being periodic over 0..twopi. The larger the argument, the fewer significant digits are left in the arg % twopi calculation. The "until C++11" annotation strikes me as wildly optimistic and neither C99 nor C++11 say anything about it. They can't. – Hans Passant Oct 12 '17 at 15:52
  • 1
    @mch: yep, that's well understood :) The question is, has something changed in C++11? Is there something about this case in the standard? – geza Oct 12 '17 at 15:54
  • in C standard: [`The result may have little or no significance if the magnitude of arg is large. (until C99)`](http://en.cppreference.com/w/c/numeric/math/sin) – phuclv Oct 12 '17 at 16:21
  • [related](/q/19644938), [related](/q/6665418), [related](/q/9423516), [related](/q/46711285) – Toby Speight Oct 13 '17 at 14:47

1 Answers1

11

C++11 switched the C standard reference from C89/C90 to C99. The original C standard used to state (quoted from a draft):

The sin function computes the sine of x (measured in radians). A large magnitude argument may yield a result with little or no significance.

In C99, this text was dropped, and the description is now merely:

The sin functions compute the sine of x (measured in radians).

I suspect the reason for dropping this is that C99 introduced the __STDC_IEC_559__ macro, which implementations can define to document their compliance to that standard. According to Standard for the sine of very large numbers, it recommends (but does not require) correct results even for large magnitude arguments. The original C standard's text could be seen as weakening that recommendation.

  • 7
    As an aside, the classical paper for argument reduction of large inputs for trigonometric functions is Ng et al, ARGUMENT REDUCTION FOR HUGE ARGUMENTS: Good to the Last Bit, https://www.csee.umbc.edu/~phatak/645/supl/Ng-ArgReduction.pdf – janneb Oct 12 '17 at 16:28