C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- std::numeric_limits
- std::numeric_limits<T>::is_integer
- std::numeric_limits<T>::is_exact
- std::numeric_limits<T>::is_specialized
- std::numeric_limits<T>::is_signed
- std::numeric_limits<T>::has_infinity
- std::numeric_limits<T>::has_quiet_NaN
- std::numeric_limits<T>::has_signaling_NaN
- std::numeric_limits<T>::has_denorm
- std::numeric_limits<T>::has_denorm_loss
- std::numeric_limits<T>::round_style
- std::numeric_limits<T>::is_iec559
- std::numeric_limits<T>::is_bounded
- std::numeric_limits<T>::is_modulo
- std::numeric_limits<T>::digits
- std::numeric_limits<T>::digits10
- std::numeric_limits<T>::max_digits10
- std::numeric_limits<T>::radix
- std::numeric_limits<T>::min_exponent
- std::numeric_limits<T>::min_exponent10
- std::numeric_limits<T>::max_exponent10
- std::numeric_limits<T>::max_exponent10
- std::numeric_limits<T>::traps
- std::numeric_limits<T>::tinyness_before
- std::numeric_limits<T>::min
- std::numeric_limits<T>::lowest
- std::numeric_limits<T>::max
- std::numeric_limits<T>::epsilon
- std::result_of, std::invoke_result
- std::integral_constant
- std::is_constant_evaluated
- std::max_align_t
- offsetof
- NULL
- std::bad_typeid
- std::bad_cast
- std::type_info
- std::ptrdiff_t
- std::byte
- std::conjunction
- std::disjunction
- std::negation
- std::is_swappable_with, std::is_swappable, std::is_nothrow_swappable_with, std::is_nothrow_swappable
- std::is_invocable, std::is_invocable_r, std::is_nothrow_invocable, std::is_nothrow_invocable_r
- std::is_aggregate
- std::has_unique_object_representations
- std::endian
- std::remove_cvref
- std::type_index
- C æ°å¼æéæ¥å£
- å®å®½æ´æ°ç±»å (C++11 èµ·)
- std::is_bounded_array
- std::is_unbounded_array
- std::size_t
- std::nullptr_t
- std::is_integral
- std::rank
- std::is_void
- std::is_null_pointer
- std::is_array
- std::is_pointer
- std::is_enum
- std::is_union
- std::is_class
- std::is_function
- std::is_object
- std::is_scalar
- std::is_compound
- std::is_floating_point
- std::is_fundamental
- std::is_arithmetic
- std::is_reference
- std::is_lvalue_reference
- std::is_rvalue_reference
- std::is_member_pointer
- std::is_member_object_pointer
- std::is_member_function_pointer
- std::is_const
- std::is_volatile
- std::is_empty
- std::is_polymorphic
- std::is_final
- std::is_abstract
- std::is_trivial
- std::is_trivially_copyable
- std::is_standard_layout
- std::is_literal_type
- std::is_pod
- std::is_signed
- std::is_unsigned
- std::is_constructible, std::is_trivially_constructible, std::is_nothrow_constructible
- std::is_default_constructible, std::is_trivially_default_constructible, std::is_nothrow_default_constructible
- std::is_copy_constructible, std::is_trivially_copy_constructible, std::is_nothrow_copy_constructible
- std::is_move_constructible, std::is_trivially_move_constructible, std::is_nothrow_move_constructible
- std::is_assignable, std::is_trivially_assignable, std::is_nothrow_assignable
- std::is_copy_assignable, std::is_trivially_copy_assignable, std::is_nothrow_copy_assignable
- std::is_move_assignable, std::is_trivially_move_assignable, std::is_nothrow_move_assignable
- std::is_destructible, std::is_trivially_destructible, std::is_nothrow_destructible
- std::has_virtual_destructor
- std::is_same
- std::is_base_of
- std::is_convertible, std::is_nothrow_convertible
- std::is_layout_compatible
- std::is_pointer_interconvertible_base_of
- std::is_pointer_interconvertible_with_class
- std::is_corresponding_member
- std::alignment_of
- std::extent
- std::remove_cv, std::remove_const, std::remove_volatile
- std::add_cv, std::add_const, std::add_volatile
- std::make_signed
- std::make_unsigned
- std::remove_reference
- std::add_lvalue_reference, std::add_rvalue_reference
- std::remove_pointer
- std::add_pointer
- std::remove_extent
- std::remove_all_extents
- std::aligned_storage
- std::aligned_union
- std::decay
- std::enable_if
- std::void_t
- std::conditional
- std::common_type
- std::common_reference
- std::underlying_type
- std::type_identity
- 注é
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼ >std::numeric_limits > std::numeric_limits<T>::round_style
std::numeric_limits<T>::round_style
| static const std::float_round_style round_style; |
(C++11 å) | |
| static constexpr std::float_round_style round_style; |
(C++11 èµ·) | |
std::numeric_limits<T>::round_style çå¼é´å«æµ®ç¹ç±»å T å¨å¡å°ä¸è½ä»¥ T çå¼è¡¨ç¤ºçå¼åå¨äºè¯¥ç±»åçå¯¹è±¡æ¶æç¨çèå
¥æ¨¡å¼ã
æ åç¹å
| Â | |
T
|
std::numeric_limits<T>::round_style çå¼ |
| /* non-specialized */ | std::round_toward_zero |
| bool | std::round_toward_zero |
| char | std::round_toward_zero |
| signed char | std::round_toward_zero |
| unsigned char | std::round_toward_zero |
| wchar_t | std::round_toward_zero |
| char8_t | std::round_toward_zero |
| char16_t | std::round_toward_zero |
| char32_t | std::round_toward_zero |
| short | std::round_toward_zero |
| unsigned short | std::round_toward_zero |
| int | std::round_toward_zero |
| unsigned int | std::round_toward_zero |
| long | std::round_toward_zero |
| unsigned long | std::round_toward_zero |
| long long | std::round_toward_zero |
| unsigned long long | std::round_toward_zero |
| float | é常为 std::round_to_nearest |
| double | é常为 std::round_to_nearest |
| long double | é常为 std::round_to_nearest |
注解
è¿äºå¼æ¯å¸¸éï¼ä¸ä¸åæ std::fesetround æåçèå ¥æ¨¡å¼æ´æ¹ãå¯ä» FLT_ROUNDS æ std::fegetround è·å¾æ´æ¹åçå¼ã
示ä¾
åè¿å¶å¼ 0.1 ä¸è½è¡¨ç¤ºæäºè¿å¶æµ®ç¹ç±»åãå¨åå¨äº IEEE-754 double æ¶ï¼å®è½å
¥ 0x1.9999999999999*2-4
ä¸ 0x1.999999999999a*2-4
ä¹é´ãèå
¥å°æè¿å¯è¡¨ç¤ºç»æå¯¼è´ 0x1.999999999999a*2-4
ã
åæ ·å°ï¼åè¿å¶å¼ 0.3 å¨ 0x1.3333333333333*2-2
ä¸ 0x1.3333333333334*2-2
ä¹é´ï¼èå
¥å°æè¿å¼ååå¨ä¸º 0x1.3333333333333*2-2
ã
#include <iostream> #include <limits> int main() { std::cout << std::hexfloat << "The decimal 0.1 is stored in a double as " << 0.1 << '\n' << "The decimal 0.3 is stored in a double as " << 0.3 << '\n' << "The rounding style is " << std::numeric_limits<double>::round_style << '\n'; }
è¾åºï¼
The decimal 0.1 is stored in a double as 0x1.999999999999ap-4 The decimal 0.3 is stored in a double as 0x1.3333333333333p-2 The rounding style is 1
åé
| æç¤ºæµ®ç¹èå
¥æ¨¡å¼ (æä¸¾) |