Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting another types #7

Open
Rain0Ash opened this issue Jun 18, 2024 · 1 comment
Open

Supporting another types #7

Rain0Ash opened this issue Jun 18, 2024 · 1 comment
Assignees

Comments

@Rain0Ash
Copy link

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants