Skip to content

Commit 2519259

Browse files
authored
Merge pull request #1298 from andrjohns/log-pi-constant
Add new constant `log_pi`
2 parents 4d7d6e1 + 0353afe commit 2519259

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

doc/constants/constants.qbk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ This section lists the mathematical constants, their use(s) (and sometimes ratio
340340
[[pi_minus_three] [[pi]-3] [0.141593] [] ]
341341
[[four_minus_pi] [4 -[pi]] [0.858407] [] ]
342342
[[pi_pow_e] [[pi][super e]] [22.4591] [] ]
343+
[[log_pi] [ln([pi])] [1.14473] [] ]
343344

344345
[[pi_sqr] [[pi][super 2]] [9.86960] [] ]
345346
[[pi_sqr_div_six] [[pi][super 2]/6] [1.64493] [] ]

include/boost/math/constants/calculate_constants.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ inline T constant_one_div_two_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_S
9595
return 1 / two_pi<T, policies::policy<policies::digits2<N> > >();
9696
}
9797

98+
template <class T>
99+
template<int N>
100+
inline T constant_log_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
101+
{
102+
BOOST_MATH_STD_USING
103+
return log(pi<T, policies::policy<policies::digits2<N> > >());
104+
}
105+
98106
template <class T>
99107
template<int N>
100108
inline T constant_root_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))

include/boost/math/constants/constants.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ namespace constants {
280280
BOOST_DEFINE_MATH_CONSTANT(four_thirds_pi, 4.188790204786390984616857844372670512e+00, "4.18879020478639098461685784437267051226289253250014109463325945641042187504827866483737976712282275730953078202e+00")
281281
BOOST_DEFINE_MATH_CONSTANT(one_div_two_pi, 1.591549430918953357688837633725143620e-01, "1.59154943091895335768883763372514362034459645740456448747667344058896797634226535090113802766253085956072842727e-01")
282282
BOOST_DEFINE_MATH_CONSTANT(one_div_root_two_pi, 3.989422804014326779399460599343818684e-01, "3.98942280401432677939946059934381868475858631164934657665925829670657925899301838501252333907306936430302558863e-01")
283+
BOOST_DEFINE_MATH_CONSTANT(log_pi, 1.144729885849400174143427351353058711e+00, "1.14472988584940017414342735135305871164729481291531157151362307147213776988482607978362327027548970770200981223e+00")
283284
BOOST_DEFINE_MATH_CONSTANT(root_pi, 1.772453850905516027298167483341145182e+00, "1.77245385090551602729816748334114518279754945612238712821380778985291128459103218137495065673854466541622682362e+00")
284285
BOOST_DEFINE_MATH_CONSTANT(root_half_pi, 1.253314137315500251207882642405522626e+00, "1.25331413731550025120788264240552262650349337030496915831496178817114682730392098747329791918902863305800498633e+00")
285286
BOOST_DEFINE_MATH_CONSTANT(root_two_pi, 2.506628274631000502415765284811045253e+00, "2.50662827463100050241576528481104525300698674060993831662992357634229365460784197494659583837805726611600997267e+00")
@@ -357,5 +358,3 @@ BOOST_MATH_GPU_ENABLED inline constexpr T tau() { return two_pi<T>(); }
357358
#endif
358359

359360
#endif // BOOST_MATH_CONSTANTS_CONSTANTS_INCLUDED
360-
361-

test/test_constant_generate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int main()
4848
BOOST_CONSTANTS_GENERATE(four_thirds_pi);
4949
BOOST_CONSTANTS_GENERATE(one_div_two_pi);
5050
BOOST_CONSTANTS_GENERATE(one_div_root_two_pi);
51+
BOOST_CONSTANTS_GENERATE(log_pi);
5152
BOOST_CONSTANTS_GENERATE(root_pi);
5253
BOOST_CONSTANTS_GENERATE(root_half_pi);
5354
BOOST_CONSTANTS_GENERATE(root_two_pi);
@@ -189,4 +190,3 @@ Output
189190
190191
191192
*/
192-

test/test_constants.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void test_spots(RealType)
103103
BOOST_MATH_STD_USING
104104

105105
CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L, pi<RealType>(), 2);
106+
CHECK_ULP_CLOSE(log(3.14159265358979323846264338327950288419716939937510L), log_pi<RealType>(), 2);
106107
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L), root_pi<RealType>(), 2);
107108
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L/2), root_half_pi<RealType>(), 2);
108109
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L * 2), root_two_pi<RealType>(), 2);
@@ -160,6 +161,7 @@ void test_spots(RealType)
160161
CHECK_ULP_CLOSE(1 / (3.14159265358979323846264338327950288419716939937510L), one_div_pi<RealType>(), 2);
161162
CHECK_ULP_CLOSE(2 / (3.14159265358979323846264338327950288419716939937510L), two_div_pi<RealType>(), 2);
162163
CHECK_ULP_CLOSE(1 / (2 * 3.14159265358979323846264338327950288419716939937510L), one_div_two_pi<RealType>(), 2);
164+
CHECK_ULP_CLOSE(log(3.14159265358979323846264338327950288419716939937510L), log_pi<RealType>(), 2);
163165
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L), root_pi<RealType>(), 2);
164166
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L / 2), root_half_pi<RealType>(), 2);
165167
CHECK_ULP_CLOSE(sqrt(2 * 3.14159265358979323846264338327950288419716939937510L), root_two_pi<RealType>(), 2);
@@ -242,6 +244,7 @@ void test_float_spots()
242244
BOOST_MATH_STD_USING
243245

244246
CHECK_ULP_CLOSE(static_cast<float>(3.14159265358979323846264338327950288419716939937510F), pi, 2);
247+
CHECK_ULP_CLOSE(static_cast<float>(log(3.14159265358979323846264338327950288419716939937510F)), log_pi, 2);
245248
CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F)), root_pi, 2);
246249
CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F/2)), root_half_pi, 2);
247250
CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F * 2)), root_two_pi, 2);
@@ -293,6 +296,7 @@ void test_float_spots()
293296
CHECK_ULP_CLOSE(static_cast<float>(1 / (3.14159265358979323846264338327950288419716939937510F)), one_div_pi, 2);
294297
CHECK_ULP_CLOSE(static_cast<float>(2 / (3.14159265358979323846264338327950288419716939937510F)), two_div_pi, 2);
295298
CHECK_ULP_CLOSE(static_cast<float>(1 / (2 * 3.14159265358979323846264338327950288419716939937510F)), one_div_two_pi, 2);
299+
CHECK_ULP_CLOSE(static_cast<float>(log(3.14159265358979323846264338327950288419716939937510F)), log_pi, 2);
296300
CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F)), root_pi, 2);
297301
CHECK_ULP_CLOSE(static_cast<float>(sqrt(3.14159265358979323846264338327950288419716939937510F / 2)), root_half_pi, 2);
298302
CHECK_ULP_CLOSE(static_cast<float>(sqrt(2 * 3.14159265358979323846264338327950288419716939937510F)), root_two_pi, 2);
@@ -362,6 +366,7 @@ void test_f32_spots()
362366
BOOST_MATH_STD_USING
363367

364368
CHECK_ULP_CLOSE(static_cast<std::float32_t>(3.14159265358979323846264338327950288419716939937510F32), pi, 2);
369+
CHECK_ULP_CLOSE(static_cast<std::float32_t>(log(3.14159265358979323846264338327950288419716939937510F32)), log_pi, 2);
365370
CHECK_ULP_CLOSE(static_cast<std::float32_t>(sqrt(3.14159265358979323846264338327950288419716939937510F32)), root_pi, 2);
366371
CHECK_ULP_CLOSE(static_cast<std::float32_t>(sqrt(3.14159265358979323846264338327950288419716939937510F32/2)), root_half_pi, 2);
367372
CHECK_ULP_CLOSE(static_cast<std::float32_t>(sqrt(3.14159265358979323846264338327950288419716939937510F32 * 2)), root_two_pi, 2);
@@ -413,6 +418,7 @@ void test_f32_spots()
413418
CHECK_ULP_CLOSE(static_cast<std::float32_t>(1 / (3.14159265358979323846264338327950288419716939937510F32)), one_div_pi, 2);
414419
CHECK_ULP_CLOSE(static_cast<std::float32_t>(2 / (3.14159265358979323846264338327950288419716939937510F32)), two_div_pi, 2);
415420
CHECK_ULP_CLOSE(static_cast<std::float32_t>(1 / (2 * 3.14159265358979323846264338327950288419716939937510F32)), one_div_two_pi, 2);
421+
CHECK_ULP_CLOSE(static_cast<std::float32_t>(log(3.14159265358979323846264338327950288419716939937510F32)), log_pi, 2);
416422
CHECK_ULP_CLOSE(static_cast<std::float32_t>(sqrt(3.14159265358979323846264338327950288419716939937510F32)), root_pi, 2);
417423
CHECK_ULP_CLOSE(static_cast<std::float32_t>(sqrt(3.14159265358979323846264338327950288419716939937510F32 / 2)), root_half_pi, 2);
418424
CHECK_ULP_CLOSE(static_cast<std::float32_t>(sqrt(2 * 3.14159265358979323846264338327950288419716939937510F32)), root_two_pi, 2);
@@ -482,6 +488,7 @@ void test_double_spots()
482488
BOOST_MATH_STD_USING
483489

484490
CHECK_ULP_CLOSE(static_cast<double>(3.14159265358979323846264338327950288419716939937510), pi, 2);
491+
CHECK_ULP_CLOSE(static_cast<double>(log(3.14159265358979323846264338327950288419716939937510)), log_pi, 2);
485492
CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510)), root_pi, 2);
486493
CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510/2)), root_half_pi, 2);
487494
CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510 * 2)), root_two_pi, 2);
@@ -533,6 +540,7 @@ void test_double_spots()
533540
CHECK_ULP_CLOSE(static_cast<double>(1 / (3.14159265358979323846264338327950288419716939937510)), one_div_pi, 2);
534541
CHECK_ULP_CLOSE(static_cast<double>(2 / (3.14159265358979323846264338327950288419716939937510)), two_div_pi, 2);
535542
CHECK_ULP_CLOSE(static_cast<double>(1 / (2 * 3.14159265358979323846264338327950288419716939937510)), one_div_two_pi, 2);
543+
CHECK_ULP_CLOSE(static_cast<double>(log(3.14159265358979323846264338327950288419716939937510)), log_pi, 2);
536544
CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510)), root_pi, 2);
537545
CHECK_ULP_CLOSE(static_cast<double>(sqrt(3.14159265358979323846264338327950288419716939937510 / 2)), root_half_pi, 2);
538546
CHECK_ULP_CLOSE(static_cast<double>(sqrt(2 * 3.14159265358979323846264338327950288419716939937510)), root_two_pi, 2);
@@ -601,6 +609,7 @@ void test_f64_spots()
601609
BOOST_MATH_STD_USING
602610

603611
CHECK_ULP_CLOSE(static_cast<std::float64_t>(3.14159265358979323846264338327950288419716939937510F64), pi, 2);
612+
CHECK_ULP_CLOSE(static_cast<std::float64_t>(log(3.14159265358979323846264338327950288419716939937510F64)), log_pi, 2);
604613
CHECK_ULP_CLOSE(static_cast<std::float64_t>(sqrt(3.14159265358979323846264338327950288419716939937510F64)), root_pi, 2);
605614
CHECK_ULP_CLOSE(static_cast<std::float64_t>(sqrt(3.14159265358979323846264338327950288419716939937510F64/2)), root_half_pi, 2);
606615
CHECK_ULP_CLOSE(static_cast<std::float64_t>(sqrt(3.14159265358979323846264338327950288419716939937510F64 * 2)), root_two_pi, 2);
@@ -652,6 +661,7 @@ void test_f64_spots()
652661
CHECK_ULP_CLOSE(static_cast<std::float64_t>(1 / (3.14159265358979323846264338327950288419716939937510F64)), one_div_pi, 2);
653662
CHECK_ULP_CLOSE(static_cast<std::float64_t>(2 / (3.14159265358979323846264338327950288419716939937510F64)), two_div_pi, 2);
654663
CHECK_ULP_CLOSE(static_cast<std::float64_t>(1 / (2 * 3.14159265358979323846264338327950288419716939937510F64)), one_div_two_pi, 2);
664+
CHECK_ULP_CLOSE(static_cast<std::float64_t>(log(3.14159265358979323846264338327950288419716939937510F64)), log_pi, 2);
655665
CHECK_ULP_CLOSE(static_cast<std::float64_t>(sqrt(3.14159265358979323846264338327950288419716939937510F64)), root_pi, 2);
656666
CHECK_ULP_CLOSE(static_cast<std::float64_t>(sqrt(3.14159265358979323846264338327950288419716939937510F64 / 2)), root_half_pi, 2);
657667
CHECK_ULP_CLOSE(static_cast<std::float64_t>(sqrt(2 * 3.14159265358979323846264338327950288419716939937510F64)), root_two_pi, 2);
@@ -724,6 +734,7 @@ void test_long_double_spots()
724734
BOOST_MATH_STD_USING
725735

726736
CHECK_ULP_CLOSE(static_cast<long double>(3.14159265358979323846264338327950288419716939937510L), pi, 2);
737+
CHECK_ULP_CLOSE(static_cast<long double>(log(3.14159265358979323846264338327950288419716939937510L)), log_pi, 2);
727738
CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L)), root_pi, 2);
728739
CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L/2)), root_half_pi, 2);
729740
CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L * 2)), root_two_pi, 2);
@@ -775,6 +786,7 @@ void test_long_double_spots()
775786
CHECK_ULP_CLOSE(static_cast<long double>(1 / (3.14159265358979323846264338327950288419716939937510L)), one_div_pi, 2);
776787
CHECK_ULP_CLOSE(static_cast<long double>(2 / (3.14159265358979323846264338327950288419716939937510L)), two_div_pi, 2);
777788
CHECK_ULP_CLOSE(static_cast<long double>(1 / (2 * 3.14159265358979323846264338327950288419716939937510L)), one_div_two_pi, 2);
789+
CHECK_ULP_CLOSE(static_cast<long double>(log(3.14159265358979323846264338327950288419716939937510L)), log_pi, 2);
778790
CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L)), root_pi, 2);
779791
CHECK_ULP_CLOSE(static_cast<long double>(sqrt(3.14159265358979323846264338327950288419716939937510L / 2)), root_half_pi, 2);
780792
CHECK_ULP_CLOSE(static_cast<long double>(sqrt(2 * 3.14159265358979323846264338327950288419716939937510L)), root_two_pi, 2);
@@ -851,6 +863,7 @@ void test_real_concept_policy(const Policy&)
851863
BOOST_MATH_STD_USING
852864

853865
CHECK_ULP_CLOSE(3.14159265358979323846264338327950288419716939937510L, (pi<real_concept, Policy>)(), 2);
866+
CHECK_ULP_CLOSE(log(3.14159265358979323846264338327950288419716939937510L), (log_pi<real_concept, Policy>)(), 2);
854867
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L), (root_pi<real_concept, Policy>)(), 2);
855868
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L/2), (root_half_pi<real_concept, Policy>)(), 2);
856869
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L * 2), (root_two_pi<real_concept, Policy>)(), 2);
@@ -902,6 +915,7 @@ void test_real_concept_policy(const Policy&)
902915
CHECK_ULP_CLOSE(1 / (3.14159265358979323846264338327950288419716939937510L), (one_div_pi<real_concept, Policy>)(), 2);
903916
CHECK_ULP_CLOSE(2 / (3.14159265358979323846264338327950288419716939937510L), (two_div_pi<real_concept, Policy>)(), 2);
904917
CHECK_ULP_CLOSE(1 / (2 * 3.14159265358979323846264338327950288419716939937510L), (one_div_two_pi<real_concept, Policy>)(), 2);
918+
CHECK_ULP_CLOSE(log(3.14159265358979323846264338327950288419716939937510L), (log_pi<real_concept, Policy>)(), 2);
905919
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L), (root_pi<real_concept, Policy>)(), 2);
906920
CHECK_ULP_CLOSE(sqrt(3.14159265358979323846264338327950288419716939937510L / 2), (root_half_pi<real_concept, Policy>)(), 2);
907921
CHECK_ULP_CLOSE(sqrt(2 * 3.14159265358979323846264338327950288419716939937510L), (root_two_pi<real_concept, Policy>)(), 2);

0 commit comments

Comments
 (0)