Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/cppad/core/base_limits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ template <> class numeric_limits<Base>\
{ return static_cast<Base>( std::numeric_limits<Other>::quiet_NaN() ); }\
static Base infinity(void) \
{ return static_cast<Base>( std::numeric_limits<Other>::infinity() ); }\
static const int digits = std::numeric_limits<Other>::digits;\
static const int digits10 = std::numeric_limits<Other>::digits10;\
static const int max_digits10 = std::numeric_limits<Other>::max_digits10;\
};
Expand Down
16 changes: 15 additions & 1 deletion include/cppad/core/numeric_limits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Syntax
| *max* = ``numeric_limits`` < *Float* >:: ``max`` ()
| *nan* = ``numeric_limits`` < *Float* >:: ``quiet_NaN`` ()
| *inf* = ``numeric_limits`` < *Float* >:: ``infinity`` ()
| ``numeric_limits`` < *Float* >:: ``digits``
| ``numeric_limits`` < *Float* >:: ``digits10``
| ``numeric_limits`` < *Float* >:: ``max_digits10``

Expand All @@ -35,7 +36,7 @@ The functions above and have the prototype
where *fun* is
``epsilon`` , ``min`` , ``max`` , ``quiet_NaN`` , and ``infinity`` .

The values ``digits10`` and ``max_digits10`` are
The values ``digits`` , ``digits10`` , and ``max_digits10`` are
member variable and not a functions.

std::numeric_limits
Expand Down Expand Up @@ -128,6 +129,15 @@ tests the value *inf* by checking that the following are true
| |tab| *inf* + 100 == *inf*
| |tab| ``isnan`` ( *inf* ``-`` *inf* )

digits
******
The member variable ``digits`` has prototype

``static const int numeric_limits`` < *Float* >:: ``digits``

It is the number of base-radix digits that can be represented by a
*Float* value without change; this is the digits of the mantissa.

digits10
********
The member variable ``digits10`` has prototype
Expand Down Expand Up @@ -219,6 +229,8 @@ class numeric_limits {
);
return Float(0);
}
/// number of base-radix digits
static const int digits = -1;
/// number of decimal digits
static const int digits10 = -1;
};
Expand All @@ -242,6 +254,8 @@ class numeric_limits< AD<Base> > {
/// positive infinite value
static AD<Base> infinity(void)
{ return AD<Base>( numeric_limits<Base>::infinity() ); }
/// number of base-radix digits
static const int digits = numeric_limits<Base>::digits;
/// number of decimal digits
static const int digits10 = numeric_limits<Base>::digits10;
static const int max_digits10 = numeric_limits<Base>::max_digits10;
Expand Down
4 changes: 4 additions & 0 deletions include/cppad/example/cppad_eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ namespace Eigen {
static CppAD::AD<Base> highest(void)
{ return CppAD::numeric_limits< CppAD::AD<Base> >::max(); }

// number of base-radix digits that can be represented without change.
static int digits(void)
{ return CppAD::numeric_limits< CppAD::AD<Base> >::digits; }

// number of decimal digits that can be represented without change.
static int digits10(void)
{ return CppAD::numeric_limits< CppAD::AD<Base> >::digits10; }
Expand Down
3 changes: 3 additions & 0 deletions test_more/general/base_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ bool test_numeric_limits(void)
base_alloc nan = Value( CppAD::numeric_limits<my_ad>::quiet_NaN() );
ok &= *nan.ptrdbl_ != *nan.ptrdbl_;
//
int digits = CppAD::numeric_limits<my_ad>::digits;
ok &= digits == std::numeric_limits<double>::digits;
//
int digits10 = CppAD::numeric_limits<my_ad>::digits10;
ok &= digits10 == std::numeric_limits<double>::digits10;
//
Expand Down
Loading