AntonovAnton / math.trigonometric

This C# library includes functions that are missing in .NET: cot, sec, csc, acot, asec, acsc, coth, sech, csch, acoth, asech, and acsch. Also, it includes standard functions: sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, and atanh.
MIT License
4 stars 0 forks source link

Supporting another types #7

Open Rain0Ash opened 4 weeks ago

Rain0Ash commented 4 weeks ago

Hi, I would like to request the addition of support for the following data types:

  1. Decimal
  2. Complex
  3. Single
  4. Half

These types would enhance the flexibility and functionality of the project by allowing for more precise and varied data representations.

AntonovAnton commented 3 weeks ago

Using the decimal type for trigonometric functions in .NET is generally not advisable for several reasons:

Precision and Range: The decimal type in .NET is designed for financial and monetary calculations where precision is more critical than range. It provides a high level of precision but at the expense of range and performance. Trigonometric functions, on the other hand, often require a wide range of values, especially when dealing with angles measured in radians. The limited range of decimal can lead to inaccuracies or overflow errors when dealing with large or very small numbers.

Performance: The decimal type is significantly slower than the double type because it uses a base-10 representation internally, which requires more complex arithmetic operations. Trigonometric functions involve a lot of mathematical computations, and using decimal would slow down these calculations considerably compared to using double, which is optimized for such operations.

Library Support: Most of the mathematical libraries and functions in .NET are optimized for double and float types. The .NET Math library, for example, provides trigonometric functions (Math.Sin, Math.Cos, Math.Tan, etc.) that accept double as input. There are no built-in trigonometric functions for decimal, meaning that if you want to use decimal for trigonometry, you would need to implement these functions yourself, which is non-trivial and error-prone.

Accuracy: Trigonometric functions often involve irrational numbers and require a high degree of precision over a wide range of values. The floating-point types (double and float) are designed to handle these scenarios effectively using binary floating-point representation. The decimal type, with its decimal (base-10) representation, is not as well-suited for the kinds of calculations that trigonometric functions require. The precision of double (approximately 15-16 decimal digits) is usually sufficient for most trigonometric calculations, and the inherent inaccuracies in floating-point arithmetic are generally acceptable within this context.

In summary, the decimal type in .NET is not well-suited for trigonometric functions due to its limited range, slower performance, lack of library support, and potential issues with accuracy in the context of the wide-ranging and precise nature of trigonometric calculations. The double type is typically the better choice for these purposes.