Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ to_int() [2/3]

template<typename T , require_floating_point_t< T > * = nullptr>
int stan::math::to_int ( x)
inline

Returns the input scalar as an integer type.

This function performs no rounding and simply truncates the decimal to return only the signficand as an integer.

Casting NaN and Inf values to integers is considered undefined behavior as NaN and Inf cannot be represented as an integer and most implementations simply overflow, as such this function throws for these inputs.

The function also throws for floating-point values that are too large to be represented as an integer.

Template Parameters
Ttype of argument (must be arithmetic)
Parameters
xargument
Returns
Integer value of argument
Exceptions
std::domain_errorfor NaN, Inf, or floating point values not in range to be represented as int

Definition at line 42 of file to_int.hpp.