Skip to content

Conversation

tompng
Copy link
Member

@tompng tompng commented Jun 1, 2025

Implement these methods

BigMath.cbrt(x, prec)
BigMath.hypot(x, y, prec)
BigMath.tan(x, prec)
BigMath.asin(x, prec)
BigMath.acos(x, prec)
BigMath.atan2(y, x, prec)
BigMath.sinh(x, prec)
BigMath.cosh(x, prec)
BigMath.tanh(x, prec)
BigMath.asinh(x, prec)
BigMath.acosh(x, prec)
BigMath.atanh(x, prec)
BigMath.log2(x, prec)
BigMath.log10(x, prec)

Remaining methods

Math.singleton_methods - BigMath.singleton_methods
# => [:erf, :erfc, :gamma, :lgamma, :frexp, :ldexp]

@tompng tompng force-pushed the implement_major_math_functions branch from 1a93b02 to 5ebf5dc Compare June 8, 2025 06:30
@mrkn mrkn added this to the v3.4 milestone Jun 17, 2025
@tompng tompng force-pushed the implement_major_math_functions branch 2 times, most recently from f29ba89 to 316d713 Compare June 20, 2025 18:56
return BigDecimal::NAN if x.nan?
return BigDecimal::INFINITY if x.infinite? == 1

prec2 = prec + BigDecimal.double_fig * 3 / 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why do we decide what prec2 is needed? It differs between the functions and I'm wondering how it's calculated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, BigMath functions calculate with prec+BigDecimal.double_fig precision.

I think BigMath.log2(1024, prec) is expected to return exactly 10. To calculate exact value for 2**n numbers, we need to round the result to precision = prec+BigDecimal.double_fig.
log(x)/log(2) should be calculated with prec + BigDecimal.double_fig + extra precision.
I decided to use extra=BigDeciaml.double_fig/2 here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tompng tompng force-pushed the implement_major_math_functions branch from 316d713 to a2f13fa Compare June 21, 2025 08:05
@tompng tompng force-pushed the implement_major_math_functions branch from a2f13fa to 4385bbd Compare June 30, 2025 11:10
tompng added 3 commits July 19, 2025 23:21
Calculate `tan(x, prec)` by `relative_precision_sin/relative_precision_cos`.
@tompng tompng force-pushed the implement_major_math_functions branch from 4385bbd to 1c37330 Compare July 19, 2025 14:35
@tompng tompng force-pushed the implement_major_math_functions branch from 1c37330 to f9b5a97 Compare July 19, 2025 15:01
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

Successfully merging this pull request may close these issues.

3 participants