YSTest: rational.hpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

rational.hpp
浏览该文件的文档.
1 /*
2 © 2011-2017, 2019 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_rational_hpp_
29 #define YB_INC_ystdex_rational_hpp_ 1
30
31 #include "cstdint.hpp" // for operators, true_, false_, make_width_int,
32 // std::common_type, common_type_t, std::numeric_limits;
33 #include <libdefect/cmath.h> // for std::llround;
34 #include <functional> // for std::hash;
35
36 namespace ystdex
37 {
38
40
41
43 template<typename _type>
44 yconstfn yimpl(enable_if_t)<is_floating_point<_type>::value, bool>
45 is_zero(_type x)
46 {
47 return std::fpclassify(x) == FP_ZERO;
48 }
49 template<typename _type,
50 yimpl(typename = enable_if_t<!is_floating_point<_type>::value>)>
51 yconstfn bool
52 is_zero(_type x)
53 {
54 return x == _type(0);
55 }
57
58
69 template<typename _type>
70 yconstfn _type
71 round_in_nocheck(_type x, _type err)
72 {
73 using std::round;
74
75 return round(x / err) * err;
76 }
77
78 template<typename _type>
79 yconstfn _type
80 round_in(_type x, _type err)
81 {
82 return ystdex::is_zero(err) ? x : ystdex::round_in_nocheck(x, err);
83 }
85
86
88 template<typename _type>
89 yconstfn _type
90 pow_int(_type x, size_t n)
91 {
92 return n != 0 ? (pow_int(x, n / 2) * pow_int(x, n / 2)
93 * (n % 2 == 1 ? _type(x) : _type(1))) : _type(1);
94 }
95
97 template<typename _type>
98 yconstfn _type
99 square(_type x)
100 {
101 return x * x;
102 }
103
105 template<typename _type>
106 yconstfn _type
107 cube(_type x)
108 {
109 return x * x * x;
110 }
111
113 template<typename _type>
114 yconstfn _type
115 quad(_type x)
116 {
117 return ystdex::square(ystdex::square(x));
118 }
120
121
127 template<typename _type>
128 struct is_normalizable : or_<is_floating_point<_type>>
129 {};
130
131
132 #define YB_Impl_Rational_fp_T fixed_point<_tBase, _vInt, _vFrac>
133 #define YB_Impl_Rational_fp_T1 fixed_point<_tBase1, _vInt1, _vFrac1>
134 #define YB_Impl_Rational_fp_T2 fixed_point<_tBase2, _vInt2, _vFrac2>
135 #define YB_Impl_Rational_fp_PList \
136 typename _tBase, size_t _vInt, size_t _vFrac
137 #define YB_Impl_Rational_fp_PList1 \
138 typename _tBase1, size_t _vInt1, size_t _vFrac1
139 #define YB_Impl_Rational_fp_PList2 \
140 typename _tBase2, size_t _vInt2, size_t _vFrac2
141
160 template<typename _tBase = std::int32_t,
161 size_t _vInt = std::numeric_limits<_tBase>::digits - 6U,
162 size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
163 class fixed_point : private operators<YB_Impl_Rational_fp_T>
164 {
165 static_assert(is_integral<_tBase>(), "Non-integral type found.");
166 static_assert(_vInt < size_t(std::numeric_limits<_tBase>::digits),
167 "No sufficient fractional bits found.");
168 static_assert(_vInt + _vFrac == size_t(std::numeric_limits<_tBase>::digits),
169 "Wrong total bits found.");
170
171 template<typename, size_t, size_t>
172 friend class fixed_point;
173 friend class std::numeric_limits<YB_Impl_Rational_fp_T>;
174
175 public:
176 using base_type = _tBase;
177
179 static yconstexpr const size_t int_bit_n = _vInt;
181 static yconstexpr const size_t frac_bit_n = _vFrac;
183 static yconstexpr const size_t digit_bit_n = int_bit_n + frac_bit_n;
184
185 private:
186 base_type value;
187
188 public:
193 fixed_point() = default;
195 yconstfn
196 fixed_point(base_type v, raw_tag) ynothrow
197 : value(v)
198 {}
200 template<typename _tInt>
201 yconstfn
202 fixed_point(_tInt val,
203 yimpl(enable_if_t<is_integral<_tInt>::value, _tInt*> = {})) ynothrowv
204 // XXX: Conversion to 'base_type' might be implementation-defined if
205 // it is signed.
206 : value(base_type(val << frac_bit_n))
207 {}
209
210 template<typename _tFloat>
211 explicit yconstfn
212 fixed_point(_tFloat val, yimpl(enable_if_t<
213 is_floating_point<_tFloat>::value, _tFloat*> = {})) ynothrow
214 : value(base_type(std::llround(base_element() * val)))
215 {}
216 template<typename _tFirst, typename _tSecond>
218
219 yconstfn
220 fixed_point(_tFirst x, _tSecond y, yimpl(enable_if_t<and_<is_integral<
221 _tFirst>, not_<is_same<_tSecond, raw_tag>>>::value, _tFirst*> = {}))
222 ynothrowv
223 : value((x << frac_bit_n) / y)
224 {}
225 template<typename _tFirst, typename _tSecond>
226 explicit yconstfn
227 fixed_point(_tFirst x, _tSecond y, yimpl(enable_if_t<and_<is_floating_point<
228 _tFirst>, not_<is_same<_tSecond, raw_tag>>>::value, _tFirst*> = {}))
229 ynothrowv
230 : fixed_point(x / y)
231 {}
233 yconstfn
235 fixed_point(const fixed_point&) = default;
236 template<size_t _vOtherInt, size_t _vOtherFrac>
237 yconstfn
238 fixed_point(const fixed_point<base_type, _vOtherInt, _vOtherFrac>& f,
239 yimpl(enable_if_t<(_vOtherInt < int_bit_n), base_type*> = {})) ynothrow
240 : value(f.value >> (int_bit_n - _vOtherInt))
241 {}
242 template<size_t _vOtherInt, size_t _vOtherFrac>
243 yconstfn
244 fixed_point(const fixed_point<base_type, _vOtherInt, _vOtherFrac>& f,
245 yimpl(enable_if_t<(int_bit_n < _vOtherInt), base_type*> = {})) ynothrow
246 : value(f.value << (_vOtherInt - int_bit_n))
247 {}
248 template<typename _tOtherBase, size_t _vOtherInt, size_t _vOtherFrac>
249 yconstfn
250 fixed_point(const fixed_point<_tOtherBase, _vOtherInt, _vOtherFrac>& f,
251 yimpl(enable_if_t<(frac_bit_n == _vOtherFrac), base_type*> = {}))
252 ynothrow
253 : value(f.value)
254 {}
255 template<typename _tOtherBase, size_t _vOtherInt, size_t _vOtherFrac>
256 yconstfn
257 fixed_point(const fixed_point<_tOtherBase, _vOtherInt, _vOtherFrac>& f,
258 yimpl(enable_if_t<(frac_bit_n < _vOtherFrac), base_type*> = {}))
259 ynothrow
260 : value(f.value >> (_vOtherFrac - frac_bit_n))
261 {}
262 template<typename _tOtherBase, size_t _vOtherInt, size_t _vOtherFrac>
263 yconstfn
264 fixed_point(const fixed_point<_tOtherBase, _vOtherInt, _vOtherFrac>& f,
265 yimpl(enable_if_t<(_vOtherFrac < frac_bit_n), base_type*> = {}))
266 ynothrow
267 : value(f.value << (frac_bit_n - _vOtherFrac))
268 {}
270
272 fixed_point&
273 operator=(const fixed_point&) = default;
274
275 bool
276 operator<(const fixed_point& f) const ynothrow
277 {
278 return value < f.value;
279 }
280
281 bool
282 operator==(const fixed_point& f) const ynothrow
283 {
284 return value == f.value;
285 }
286
287 bool
288 operator!() const ynothrow
289 {
290 return value == 0;
291 }
292
293 fixed_point
294 operator-() const ynothrow
295 {
296 fixed_point result;
297
298 result.value = -value;
299 return result;
300 }
301
303
304 fixed_point&
305 operator++() ynothrowv
306 {
307 value += base_element();
308 return *this;
309 }
310
311 fixed_point&
312 operator--() ynothrowv
313 {
314 value -= base_element();
315 return *this;
316 }
317
318 fixed_point&
319 operator+=(const fixed_point& f) ynothrowv
320 {
321 value += f.value;
322 return *this;
323 }
324
325 fixed_point&
326 operator-=(const fixed_point& f) ynothrowv
327 {
328 value -= f.value;
329 return *this;
330 }
331
332 fixed_point&
333 operator*=(const fixed_point& f) ynothrowv
334 {
335 value = mul<frac_bit_n + is_signed<base_type>::value>(value,
336 f.value, is_signed<typename make_widen_int<base_type>::type>());
337 return *this;
338 }
339
340 fixed_point&
341 operator/=(const fixed_point& f) ynothrowv
342 {
343 using widen_type = _t<make_widen_int<base_type>>;
344
345 value = base_type((widen_type(value) << widen_type(frac_bit_n))
346 / f.value);
347 return *this;
348 }
350
351 fixed_point&
352 operator>>=(size_t s) ynothrow
353 {
354 value >>= s;
355 return *this;
356 }
357
359 fixed_point&
360 operator<<=(size_t s) ynothrowv
361 {
362 value <<= s;
363 return *this;
364 }
365
367
368 template<typename _type,
369 yimpl(typename = enable_if_t<is_integral<_type>::value>)>
370 explicit yconstfn
371 operator _type() const ynothrow
372 {
373 return _type(value >> base_type(frac_bit_n));
374 }
375 template<typename _type, yimpl(typename _type2 = _type,
376 typename = enable_if_t<is_floating_point<_type2>::value>)>
377 yconstfn
378 operator _type() const ynothrow
379 {
380 return _type(value) / base_element();
381 }
383
385 friend yconstfn fixed_point
386 abs(fixed_point x) ynothrow
387 {
388 return fabs(x);
389 }
390
396 static yconstfn base_type
397 base_element() ynothrow
398 {
399 return base_type(1) << frac_bit_n;
400 }
401
402 friend yconstfn fixed_point
403 ceil(fixed_point x) ynothrow
404 {
405 return fixed_point(
406 (x.value + base_element() - 1) & ~(base_element() - 1), raw_tag());
407 }
408
409 friend yconstfn fixed_point
410 fabs(fixed_point x) ynothrow
411 {
412 return x.value < 0 ? -x : x;
413 }
414
415 friend yconstfn fixed_point
416 floor(fixed_point x) ynothrow
417 {
418 return fixed_point(x.value & ~(base_element() - 1), raw_tag());
419 }
420
422 yconstfn base_type
423 get() const ynothrow
424 {
425 return value;
426 }
427
433 static yconstfn fixed_point
434 identity() ynothrow
435 {
436 return fixed_point(base_element());
437 }
438
439 private:
441 template<size_t _vShiftBits>
442 static yconstfn base_type
443 mul(base_type x, base_type y, true_) ynothrowv
444 {
445 return mul_signed<_vShiftBits>(
446 _t<make_widen_int<base_type>>(x * y));
447 }
449 template<size_t _vShiftBits>
450 static yconstfn base_type
451 mul(base_type x, base_type y, false_) ynothrowv
452 {
453 // NOTE: Only fit for unsigned type, due to there exists
454 // implementation-defined behavior in conversion and right shifting on
455 // operands of signed types.
456 return base_type((_t<make_widen_int<base_type>>(x) * y)
457 >> _vShiftBits);
458 }
459
461 template<size_t _vShiftBits>
462 static yconstfn base_type
463 mul_signed(_t<make_widen_int<base_type>> tmp) ynothrowv
464 {
465 return base_type(tmp < 0 ? -(-tmp >> _vShiftBits) : tmp >> _vShiftBits);
466 }
467
468 public:
469 friend yconstfn fixed_point
470 round(fixed_point x) ynothrow
471 {
472 return fixed_point((x.value + (base_element() >> 1))
473 & ~(base_element() - 1), raw_tag());
474 }
475 };
476
477 // XXX: These operators may be better in class definition to allow only ADL, for
478 // less name pollution and better diagnostics for failure on calling overloads
479 // of them. However, templates with different function parameters whose
480 // template argument list is specified explicitly for 'fixed_point' (needed to
481 // avoid ambiguity on call for function arguement of two different instances of
482 // 'fixed_point') cannot be put into class definition without redefiniton error
483 // on instantiation. They also cannot be solely defined out of class definition
484 // because name lookup cannot find both in-class and out-of-class declarations
485 // without ambiguity.
487
488 #define YB_Impl_Rational_fp_TmplHead_2 \
489 template<YB_Impl_Rational_fp_PList1, YB_Impl_Rational_fp_PList2>
490 #define YB_Impl_Rational_fp_TmplHead_2_l \
491 template<YB_Impl_Rational_fp_PList, typename _type>
492 #define YB_Impl_Rational_fp_TmplHead_2_r \
493 template<typename _type, YB_Impl_Rational_fp_PList>
494 #define YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
495 { \
496 using result_type \
497 = common_type_t<decay_t<decltype(x)>, decay_t<decltype(y)>>; \
498 \
499 return result_type(x) _op result_type(y); \
500 }
501 #define YB_Impl_Rational_fp_TmplSig_2(_op) \
502 operator _op(const YB_Impl_Rational_fp_T1& x, \
503 const YB_Impl_Rational_fp_T2& y)
504 #define YB_Impl_Rational_fp_TmplSig_2_l(_op) \
505 operator _op(const YB_Impl_Rational_fp_T& x, const _type& y)
506 #define YB_Impl_Rational_fp_TmplSig_2_r(_op) \
507 operator _op(const _type& x, const YB_Impl_Rational_fp_T& y)
508
514 #define YB_Impl_Rational_fp_arithmetic2(_op) \
515 YB_Impl_Rational_fp_TmplHead_2 \
516 yconstfn common_type_t<YB_Impl_Rational_fp_T1, YB_Impl_Rational_fp_T2> \
517 YB_Impl_Rational_fp_TmplSig_2(_op) \
518 YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
519 \
520 YB_Impl_Rational_fp_TmplHead_2_l \
521 yconstfn enable_if_t<is_arithmetic<_type>::value, \
522 common_type_t<YB_Impl_Rational_fp_T, _type>> \
523 YB_Impl_Rational_fp_TmplSig_2_l(_op) \
524 YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
525 \
526 YB_Impl_Rational_fp_TmplHead_2_r \
527 yconstfn enable_if_t<is_arithmetic<_type>::value, \
528 common_type_t<_type, YB_Impl_Rational_fp_T>> \
529 YB_Impl_Rational_fp_TmplSig_2_r(_op) \
530 YB_Impl_Rational_fp_TmplBody_Impl_2(_op)
531
532 YB_Impl_Rational_fp_arithmetic2(+)
533 YB_Impl_Rational_fp_arithmetic2(-)
534 YB_Impl_Rational_fp_arithmetic2(*)
535 YB_Impl_Rational_fp_arithmetic2(/)
536
537 #undef YB_Impl_Rational_fp_ar2
538
539
545 #define YB_Impl_Rational_fp_rational2(_op) \
546 YB_Impl_Rational_fp_TmplHead_2 \
547 yconstfn bool \
548 YB_Impl_Rational_fp_TmplSig_2(_op) \
549 YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
550 \
551 YB_Impl_Rational_fp_TmplHead_2_l \
552 yconstfn bool \
553 YB_Impl_Rational_fp_TmplSig_2_l(_op) \
554 YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
555 \
556 YB_Impl_Rational_fp_TmplHead_2_r \
557 yconstfn bool \
558 YB_Impl_Rational_fp_TmplSig_2_r(_op) \
559 YB_Impl_Rational_fp_TmplBody_Impl_2(_op)
560
561 YB_Impl_Rational_fp_rational2(==)
562 YB_Impl_Rational_fp_rational2(!=)
563 YB_Impl_Rational_fp_rational2(<)
564 YB_Impl_Rational_fp_rational2(<=)
565 YB_Impl_Rational_fp_rational2(>)
566 YB_Impl_Rational_fp_rational2(>=)
567
568 #undef YB_Impl_Rational_fp_rational2
569
570
571 #undef YB_Impl_Rational_fp_TmplSig_2_r
572 #undef YB_Impl_Rational_fp_TmplSig_2_l
573 #undef YB_Impl_Rational_fp_TmplSig_2
574 #undef YB_Impl_Rational_fp_TmplBody_Impl_2
575 #undef YB_Impl_Rational_fp_TmplHead_2_r
576 #undef YB_Impl_Rational_fp_TmplHead_2_l
577 #undef YB_Impl_Rational_fp_TmplHead_2
578
579
580
586 template<YB_Impl_Rational_fp_PList>
587 struct modular_arithmetic<YB_Impl_Rational_fp_T>
588 : modular_arithmetic<typename YB_Impl_Rational_fp_T::base_type>
589 {};
590
591
596 template<YB_Impl_Rational_fp_PList>
597 struct is_normalizable<YB_Impl_Rational_fp_T> : true_
598 {};
599
600
605 template<size_t _vFrac, size_t _vInt = 1, bool _bSigned = false>
606 using make_fixed_t = fixed_point<conditional_t<_bSigned,
607 typename make_width_int<_vFrac + _vInt>::least_type,
608 typename make_width_int<_vFrac + _vInt>::unsigned_least_type>, _vFrac>;
609
610 } // namespace ystdex;
611
612 namespace std
613 {
614
620 template<YB_Impl_Rational_fp_PList1, YB_Impl_Rational_fp_PList2>
621 struct common_type<ystdex::YB_Impl_Rational_fp_T1,
622 ystdex::YB_Impl_Rational_fp_T2>
623 {
624 private:
625 using common_base_type = ystdex::common_type_t<_tBase1, _tBase2>;
626
627 static yconstexpr const size_t int_size = _vInt1 < _vInt2 ? _vInt2 : _vInt1;
628
629 public:
630 using type = ystdex::fixed_point<common_base_type, int_size,
631 std::numeric_limits<common_base_type>::digits - int_size>;
632 };
633
643 template<YB_Impl_Rational_fp_PList, typename _type>
644 struct common_type<ystdex::YB_Impl_Rational_fp_T, _type>
645 {
646 private:
647 using fixed = ystdex::YB_Impl_Rational_fp_T;
648
649 public:
650 using type = ystdex::cond_t<is_floating_point<_type>
651 #if false
652 || !(std::double_t(std::numeric_limits<fixed>::min())
653 < std::double_t(std::numeric_limits<_type>::min())
654 || std::double_t(std::numeric_limits<_type>::max())
655 < std::double_t(std::numeric_limits<fixed>::max()))
656 #endif
657 , _type, fixed>;
658 };
659
660 template<typename _type, YB_Impl_Rational_fp_PList>
661 struct common_type<_type, ystdex::YB_Impl_Rational_fp_T>
662 {
663 using type = ystdex::common_type_t<ystdex::YB_Impl_Rational_fp_T, _type>;
664 };
666
667
672 template<YB_Impl_Rational_fp_PList>
673 struct hash<ystdex::YB_Impl_Rational_fp_T>
674 {
675 size_t
676 operator()(const ystdex::YB_Impl_Rational_fp_T& k) const
677 ynoexcept_spec(yimpl(hash<_tBase>{}(k.get())))
678 {
679 return hash<_tBase>{}(k.get());
680 }
681 };
682
683
690 template<YB_Impl_Rational_fp_PList>
691 class numeric_limits<ystdex::YB_Impl_Rational_fp_T>
692 {
693 private:
694 using fp_type = ystdex::YB_Impl_Rational_fp_T;
695 using base_type = typename fp_type::base_type;
696
697 public:
698 static yconstexpr const bool is_specialized = true;
699
700 static yconstfn fp_type
701 min() ynothrow
702 {
703 return fp_type(std::numeric_limits<base_type>::min(),
704 ystdex::raw_tag());
705 }
706
707 static yconstfn fp_type
708 max() ynothrow
709 {
710 return fp_type(std::numeric_limits<base_type>::max(),
711 ystdex::raw_tag());
712 }
713
714 static yconstfn fp_type
715 lowest() ynothrow
716 {
717 return min();
718 }
719
720 static yconstexpr const int digits = _vInt;
721 static yconstexpr const int digits10 = digits * 643L / 2136;
722 static yconstexpr const int max_digits10 = 0;
723 static yconstexpr const bool is_signed
724 = numeric_limits<base_type>::is_signed;
725 static yconstexpr const bool is_integer = {};
726 static yconstexpr const bool is_exact = true;
727 static yconstexpr const int radix = 2;
728
729 static yconstfn fp_type
730 epsilon() ynothrow
731 {
732 return fp_type(1, typename ystdex::raw_tag());
733 }
734
735 static yconstfn fp_type
736 round_error() ynothrow
737 {
738 return 0.5;
739 }
740
741 static yconstexpr const int min_exponent = 0;
742 static yconstexpr const int min_exponent10 = 0;
743 static yconstexpr const int max_exponent = 0;
744 static yconstexpr const int max_exponent10 = 0;
745
746 static yconstexpr const bool has_infinity = {};
747 static yconstexpr const bool has_quiet_NaN = {};
748 static yconstexpr const bool has_signaling_NaN = has_quiet_NaN;
749 static yconstexpr const float_denorm_style has_denorm = denorm_absent;
750 static yconstexpr const bool has_denorm_loss = {};
751
752 static yconstfn fp_type
753 infinity() ynothrow
754 {
755 return 0;
756 }
757
758 static yconstfn fp_type
759 quiet_NaN() ynothrow
760 {
761 return 0;
762 }
763
764 static yconstfn fp_type
765 signaling_NaN() ynothrow
766 {
767 return 0;
768 }
769
770 static yconstfn fp_type
771 denorm_min() ynothrow
772 {
773 return 0;
774 }
775
776 static yconstexpr const bool is_iec559 = {};
777 static yconstexpr const bool is_bounded = true;
778 static yconstexpr const bool is_modulo
779 = numeric_limits<base_type>::is_modulo;
780
781 static yconstexpr const bool traps = numeric_limits<base_type>::traps;
782 static yconstexpr const bool tinyness_before = {};
783 static yconstexpr const float_round_style round_style = round_toward_zero;
784 };
785
787
788 template<YB_Impl_Rational_fp_PList>
789 class numeric_limits<const ystdex::YB_Impl_Rational_fp_T>
790 : yimpl(public) numeric_limits<ystdex::YB_Impl_Rational_fp_T>
791 {};
792
793 template<YB_Impl_Rational_fp_PList>
794 class numeric_limits<volatile ystdex::YB_Impl_Rational_fp_T>
795 : yimpl(public) numeric_limits<ystdex::YB_Impl_Rational_fp_T>
796 {};
797
798 template<YB_Impl_Rational_fp_PList>
799 class numeric_limits<const volatile ystdex::YB_Impl_Rational_fp_T>
800 : yimpl(public) numeric_limits<ystdex::YB_Impl_Rational_fp_T>
801 {};
803
804 #undef YB_Impl_Rational_fp_PList2
805 #undef YB_Impl_Rational_fp_PList1
806 #undef YB_Impl_Rational_fp_PList
807 #undef YB_Impl_Rational_fp_T2
808 #undef YB_Impl_Rational_fp_T1
809 #undef YB_Impl_Rational_fp_T
810
811 } // namespace std;
812
813 #endif
814
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::base_type
typename fp_type::base_type base_type
Definition: rational.hpp:695
YB_Impl_Rational_fp_rational2
#define YB_Impl_Rational_fp_rational2(_op)
不同模板参数的二元关系操作符。
Definition: rational.hpp:545
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::quiet_NaN
static fp_type quiet_NaN()
Definition: rational.hpp:759
ystdex::fixed_point::fixed_point
fixed_point(_tFloat val, enable_if_t< is_floating_point< _tFloat >::value, _tFloat * >={})
Definition: rational.hpp:212
x
const EncapsulationBase & x
Definition: NPLA1Forms.cpp:1536
std::common_type< ystdex::fixed_point< _tBase1, _vInt1, _vFrac1 >, ystdex::fixed_point< _tBase2, _vInt2, _vFrac2 > >::common_base_type
ystdex::common_type_t< _tBase1, _tBase2 > common_base_type
Definition: rational.hpp:625
ystdex::cpp2014::conditional_t
typename conditional< _bCond, _type, _type2 >::type conditional_t
Definition: meta.hpp:202
ystdex::quad
_type quad(_type x)
计算四次方。
Definition: rational.hpp:115
ystdex::fixed_point::identity
static fixed_point identity()
取单位元。
Definition: rational.hpp:434
ystdex::round_in_nocheck
_type round_in_nocheck(_type x, _type err)
指定误差内舍入。
Definition: rational.hpp:71
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::round_error
static fp_type round_error()
Definition: rational.hpp:736
ystdex::fixed_point::fixed_point
fixed_point(const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &f, enable_if_t<(frac_bit_n==_vOtherFrac), base_type * >={})
Definition: rational.hpp:250
ystdex::make_width_int::unsigned_least_type
typename make_width_int<(_vWidth<=8U ? 8U :(_vWidth<=16U ? 16U :(_vWidth<=32U ? 32U :64U)))> ::unsigned_least_type unsigned_least_type
Definition: cstdint.hpp:144
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
ystdex::fixed_point::fabs
friend fixed_point fabs(fixed_point x)
Definition: rational.hpp:410
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::epsilon
static fp_type epsilon()
Definition: rational.hpp:730
std::common_type< _type, ystdex::fixed_point< _tBase, _vInt, _vFrac > >::type
ystdex::common_type_t< ystdex::fixed_point< _tBase, _vInt, _vFrac >, _type > type
Definition: rational.hpp:663
ystdex::fixed_point::fixed_point
fixed_point(const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &f, enable_if_t<(_vOtherFrac< frac_bit_n), base_type * >={})
Definition: rational.hpp:264
ystdex::cpp2014::min
const _type & min(const _type &a, const _type &b, _fComp comp=less< _type >())
取较小的元素。
Definition: algorithm.hpp:614
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::min
static fp_type min()
Definition: rational.hpp:701
ystdex::is_zero
enable_if_t< is_floating_point< _type >::value, bool > is_zero(_type x)
判断指定的值是否为零值。
Definition: rational.hpp:45
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
ystdex::fixed_point::get
base_type get() const
Definition: rational.hpp:423
ystdex::fixed_point::operator<<=
fixed_point & operator<<=(size_t s)
Definition: rational.hpp:360
ystdex::fixed_point::fixed_point
friend class fixed_point
Definition: rational.hpp:165
ystdex::fixed_point::operator-=
fixed_point & operator-=(const fixed_point &f)
Definition: rational.hpp:326
ynoexcept_spec
#define ynoexcept_spec(...)
表达式 noexcept 异常规范。
Definition: ydef.h:1181
YB_Impl_Rational_fp_T1
#define YB_Impl_Rational_fp_T1
Definition: rational.hpp:133
ystdex::fixed_point::operator-
fixed_point operator-() const
Definition: rational.hpp:294
ystdex::fixed_point::operator++
fixed_point & operator++()
Definition: rational.hpp:305
ystdex::cpp2014::max
const _type & max(const _type &a, const _type &b, _fComp comp=less< _type >())
取较大的元素。
Definition: algorithm.hpp:635
ystdex::fixed_point::operator=
fixed_point & operator=(const fixed_point &)=default
ystdex::fixed_point::fixed_point
fixed_point(base_type v, raw_tag)
Definition: rational.hpp:196
ystdex::fixed_point::fixed_point
fixed_point(const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &f, enable_if_t<(frac_bit_n< _vOtherFrac), base_type * >={})
Definition: rational.hpp:257
ystdex::make_widen_int
位加倍扩展。
Definition: cstdint.hpp:203
ystdex::round_in
_type round_in(_type x, _type err)
Definition: rational.hpp:80
ystdex::pow_int
_type pow_int(_type x, size_t n)
计算整数次幂。
Definition: rational.hpp:90
CHRLib::f
f(d, s)
ystdex::fixed_point::frac_bit_n
static const size_t frac_bit_n
小数部分二进制位数。
Definition: rational.hpp:181
ystdex::fixed_point::int_bit_n
static const size_t int_bit_n
整数部分二进制位数。
Definition: rational.hpp:179
ystdex::fixed_point::ceil
friend fixed_point ceil(fixed_point x)
Definition: rational.hpp:403
ystdex::fixed_point::fixed_point
fixed_point()=default
无参数构造。
ystdex::fixed_point::operator==
bool operator==(const fixed_point &f) const
Definition: rational.hpp:282
ystdex::details::_type2
_type2
Definition: operators.hpp:241
ystdex::fixed_point::operator!
bool operator!() const
Definition: rational.hpp:288
ystdex::fixed_point::fixed_point
fixed_point(const fixed_point &)=default
ystdex::fixed_point::fixed_point
fixed_point(const fixed_point< base_type, _vOtherInt, _vOtherFrac > &f, enable_if_t<(_vOtherInt< int_bit_n), base_type * >={})
Definition: rational.hpp:238
ystdex::fixed_point::digit_bit_n
static const size_t digit_bit_n
非符号位的二进制位数。
Definition: rational.hpp:183
ystdex::or_
逻辑或。
Definition: integral_constant.hpp:172
ystdex::fixed_point::operator--
fixed_point & operator--()
Definition: rational.hpp:312
ystdex::fixed_point::fixed_point
fixed_point(_tFirst x, _tSecond y, enable_if_t< and_< is_floating_point< _tFirst >, not_< is_same< _tSecond, raw_tag >>>::value, _tFirst * >={})
Definition: rational.hpp:227
ystdex::fixed_point::operator+=
fixed_point & operator+=(const fixed_point &f)
Definition: rational.hpp:319
ystdex::fixed_point::round
friend fixed_point round(fixed_point x)
Definition: rational.hpp:470
ystdex::fixed_point
通用定点数。
Definition: rational.hpp:164
ystdex::fixed_point::operator*=
fixed_point & operator*=(const fixed_point &f)
Definition: rational.hpp:333
std
Definition: optional.h:982
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::denorm_min
static fp_type denorm_min()
Definition: rational.hpp:771
ystdex::fixed_point::operator/=
fixed_point & operator/=(const fixed_point &f)
Definition: rational.hpp:341
ystdex::raw_tag
直接构造类型（直接构造重载用）。
Definition: ydef.h:1432
ystdex::make_width_int::least_type
typename make_width_int<(_vWidth<=8U ? 8U :(_vWidth<=16U ? 16U :(_vWidth<=32U ? 32U :64U)))>::least_type least_type
Definition: cstdint.hpp:141
ystdex::fixed_point::mul
static base_type mul(base_type x, base_type y, true_)
Definition: rational.hpp:443
std::common_type< ystdex::fixed_point< _tBase, _vInt, _vFrac >, _type >::type
ystdex::cond_t< is_floating_point< _type >, _type, fixed > type
Definition: rational.hpp:657
ystdex::fixed_point::fixed_point
fixed_point(_tInt val, enable_if_t< is_integral< _tInt >::value, _tInt * >={})
Definition: rational.hpp:202
ystdex::dep_ops::operators
details::flat_ops< _type, _type2, _tOpt, totally_ordered, integer_arithmetic, bitwise > operators
Definition: operators.hpp:472
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::signaling_NaN
static fp_type signaling_NaN()
Definition: rational.hpp:765
platform::KeyCodes::DS::L
@ L
Definition: Keys.h:228
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex::fixed_point::mul_signed
static base_type mul_signed(_t< make_widen_int< base_type >> tmp)
Definition: rational.hpp:463
ystdex::true_
bool_< true > true_
Definition: integral_constant.hpp:109
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
ystdex::fixed_point::operator<
bool operator<(const fixed_point &f) const
Definition: rational.hpp:276
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::lowest
static fp_type lowest()
Definition: rational.hpp:715
ystdex::cond_t
_t< cond< _tCond, _tThen, _tElse > > cond_t
Definition: meta.hpp:794
YB_Impl_Rational_fp_T2
#define YB_Impl_Rational_fp_T2
Definition: rational.hpp:134
ystdex::fixed_point::floor
friend fixed_point floor(fixed_point x)
Definition: rational.hpp:416
ystdex::fixed_point::operator>>=
fixed_point & operator>>=(size_t s)
Definition: rational.hpp:352
ystdex::cube
_type cube(_type x)
计算立方。
Definition: rational.hpp:107
v
byte v
Definition: CharRenderer.cpp:76
YB_Impl_Rational_fp_T
#define YB_Impl_Rational_fp_T
Definition: rational.hpp:132
ystdex::fixed_point::base_element
static base_type base_element()
取 base_type 表达的单位元。
Definition: rational.hpp:397
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:1219
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::fixed_point::fixed_point
fixed_point(const fixed_point< base_type, _vOtherInt, _vOtherFrac > &f, enable_if_t<(int_bit_n< _vOtherInt), base_type * >={})
Definition: rational.hpp:244
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::max
static fp_type max()
Definition: rational.hpp:708
ystdex::square
_type square(_type x)
计算平方。
Definition: rational.hpp:99
ystdex::fixed_point< yimpl(std::uint32_t, 12U)>::base_type
yimpl(std::uint32_t, 12U) base_type
Definition: rational.hpp:176
ystdex::fixed_point::value
base_type value
Definition: rational.hpp:186
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: meta.hpp:45
ystdex::fixed_point::mul
static base_type mul(base_type x, base_type y, false_)
Definition: rational.hpp:451
ystdex::fixed_point::fixed_point
fixed_point(_tFirst x, _tSecond y, enable_if_t< and_< is_integral< _tFirst >, not_< is_same< _tSecond, raw_tag >>>::value, _tFirst * >={})
Definition: rational.hpp:220
std::hash< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::operator()
size_t operator()(const ystdex::fixed_point< _tBase, _vInt, _vFrac > &k) const
Definition: rational.hpp:676
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
YB_Impl_Rational_fp_arithmetic2
#define YB_Impl_Rational_fp_arithmetic2(_op)
不同模板参数的二元算术操作符。
Definition: rational.hpp:514
ystdex::not_
逻辑非。
Definition: integral_constant.hpp:193
ystdex::false_
bool_< false > false_
Definition: integral_constant.hpp:110
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
cmath.h
标准库实现 <cmath> 修正。
ystdex::cpp2014::common_type_t
typename common_type< _types... >::type common_type_t
Definition: meta.hpp:205
ystdex::fixed_point::abs
friend fixed_point abs(fixed_point x)
Definition: rational.hpp:386
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::infinity
static fp_type infinity()
Definition: rational.hpp:753
ystdex::modular_arithmetic
模算术特性：取得不超过模值的最大值。
Definition: cstdint.hpp:248
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
ystdex::is_normalizable
判断类型是否可满足正规化要求：在 0 和 1 之间存在值进行表示。
Definition: rational.hpp:129
ystdex::and_
逻辑操作元函数。
Definition: integral_constant.hpp:151
cstdint.hpp
ISO C 标准整数类型和相关扩展操作。