YSTest: rational.hpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

rational.hpp
浏览该文件的文档.
1 /*
2 © 2011-2016 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 make_width_int, std::common_type, common_type_t,
32 // std::numeric_limits;
33 #include "operators.hpp" // for operators;
34 #include <libdefect/cmath.h> // for std::llround;
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, bool_constant<is_signed<typename
337 make_widen_int<base_type>::type>::value>());
338 return *this;
339 }
340
341 fixed_point&
342 operator/=(const fixed_point& f) ynothrowv
343 {
344 using widen_type = _t<make_widen_int<base_type>>;
345
346 value = base_type((widen_type(value) << widen_type(frac_bit_n))
347 / f.value);
348 return *this;
349 }
351
352 fixed_point&
353 operator>>=(size_t s) ynothrow
354 {
355 value >>= s;
356 return *this;
357 }
358
360 fixed_point&
361 operator<<=(size_t s) ynothrowv
362 {
363 value <<= s;
364 return *this;
365 }
366
368
369 template<typename _type,
370 yimpl(typename = enable_if_t<is_integral<_type>::value, _type>)>
371 explicit yconstfn
372 operator _type() const ynothrow
373 {
374 return _type(value >> base_type(frac_bit_n));
375 }
376 template<typename _type, yimpl(typename _type2 = _type,
377 typename = enable_if_t<is_floating_point<_type2>::value, _type>)>
378 yconstfn
379 operator _type() const ynothrow
380 {
381 return _type(value) / base_element();
382 }
384
386
387 yconstfn base_type
388 get() const ynothrow
389 {
390 return value;
391 }
392
393 private:
394 template<size_t _vShiftBits>
395 static yconstfn base_type
396 mul(base_type x, base_type y, true_type) ynothrowv
397 {
398 return mul_signed<_vShiftBits>(
399 _t<make_widen_int<base_type>>(x * y));
400 }
401 template<size_t _vShiftBits>
402 static yconstfn base_type
403 mul(base_type x, base_type y, false_type) ynothrowv
404 {
405 // NOTE: Only fit for unsigned type, due to there exists
406 // implementation-defined behavior in conversion and right shifting on
407 // operands of signed types.
408 return base_type((_t<make_widen_int<base_type>>(x) * y)
409 >> _vShiftBits);
410 }
412
414 template<size_t _vShiftBits>
415 static yconstfn base_type
416 mul_signed(_t<make_widen_int<base_type>> tmp) ynothrowv
417 {
418 return base_type(tmp < 0 ? -(-tmp >> _vShiftBits) : tmp >> _vShiftBits);
419 }
420
421 public:
427 static yconstfn base_type
428 base_element() ynothrow
429 {
430 return base_type(1) << frac_bit_n;
431 }
432
438 static yconstfn fixed_point
439 identity() ynothrow
440 {
441 return fixed_point(base_element());
442 }
443
444 friend yconstfn fixed_point
445 fabs(fixed_point x) ynothrow
446 {
447 return x.value < 0 ? -x : x;
448 }
449
450 friend yconstfn fixed_point
451 ceil(fixed_point x) ynothrow
452 {
453 return fixed_point(
454 (x.value + base_element() - 1) & ~(base_element() - 1), raw_tag());
455 }
456
457 friend yconstfn fixed_point
458 floor(fixed_point x) ynothrow
459 {
460 return fixed_point(x.value & ~(base_element() - 1), raw_tag());
461 }
462
463 friend yconstfn fixed_point
464 round(fixed_point x) ynothrow
465 {
466 return fixed_point((x.value + (base_element() >> 1))
467 & ~(base_element() - 1), raw_tag());
468 }
469 };
470
472
473 #define YB_Impl_Rational_fp_TmplHead_2 \
474 template<YB_Impl_Rational_fp_PList1, YB_Impl_Rational_fp_PList2>
475 #define YB_Impl_Rational_fp_TmplHead_2_l \
476 template<YB_Impl_Rational_fp_PList, typename _type>
477 #define YB_Impl_Rational_fp_TmplHead_2_r \
478 template<typename _type, YB_Impl_Rational_fp_PList>
479 #define YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
480 { \
481 using result_type \
482 = common_type_t<decay_t<decltype(x)>, decay_t<decltype(y)>>; \
483 \
484 return result_type(x) _op result_type(y); \
485 }
486 #define YB_Impl_Rational_fp_TmplSig_2(_op) \
487 operator _op(const YB_Impl_Rational_fp_T1& x, \
488 const YB_Impl_Rational_fp_T2& y)
489 #define YB_Impl_Rational_fp_TmplSig_2_l(_op) \
490 operator _op(const YB_Impl_Rational_fp_T& x, const _type& y)
491 #define YB_Impl_Rational_fp_TmplSig_2_r(_op) \
492 operator _op(const _type& x, const YB_Impl_Rational_fp_T& y)
493
499 #define YB_Impl_Rational_fp_arithmetic2(_op) \
500 YB_Impl_Rational_fp_TmplHead_2 \
501 yconstfn common_type_t<YB_Impl_Rational_fp_T1, YB_Impl_Rational_fp_T2> \
502 YB_Impl_Rational_fp_TmplSig_2(_op) \
503 YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
504 \
505 YB_Impl_Rational_fp_TmplHead_2_l \
506 yconstfn enable_if_t<is_arithmetic<_type>::value, \
507 common_type_t<YB_Impl_Rational_fp_T, _type>> \
508 YB_Impl_Rational_fp_TmplSig_2_l(_op) \
509 YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
510 \
511 YB_Impl_Rational_fp_TmplHead_2_r \
512 yconstfn enable_if_t<is_arithmetic<_type>::value, \
513 common_type_t<_type, YB_Impl_Rational_fp_T>> \
514 YB_Impl_Rational_fp_TmplSig_2_r(_op) \
515 YB_Impl_Rational_fp_TmplBody_Impl_2(_op)
516
517 YB_Impl_Rational_fp_arithmetic2(+)
518 YB_Impl_Rational_fp_arithmetic2(-)
519 YB_Impl_Rational_fp_arithmetic2(*)
520 YB_Impl_Rational_fp_arithmetic2(/)
521
522 #undef YB_Impl_Rational_fp_ar2
523
524
530 #define YB_Impl_Rational_fp_rational2(_op) \
531 YB_Impl_Rational_fp_TmplHead_2 \
532 yconstfn bool \
533 YB_Impl_Rational_fp_TmplSig_2(_op) \
534 YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
535 \
536 YB_Impl_Rational_fp_TmplHead_2_l \
537 yconstfn bool \
538 YB_Impl_Rational_fp_TmplSig_2_l(_op) \
539 YB_Impl_Rational_fp_TmplBody_Impl_2(_op) \
540 \
541 YB_Impl_Rational_fp_TmplHead_2_r \
542 yconstfn bool \
543 YB_Impl_Rational_fp_TmplSig_2_r(_op) \
544 YB_Impl_Rational_fp_TmplBody_Impl_2(_op)
545
546 YB_Impl_Rational_fp_rational2(==)
547 YB_Impl_Rational_fp_rational2(!=)
548 YB_Impl_Rational_fp_rational2(<)
549 YB_Impl_Rational_fp_rational2(<=)
550 YB_Impl_Rational_fp_rational2(>)
551 YB_Impl_Rational_fp_rational2(>=)
552
553 #undef YB_Impl_Rational_fp_rational2
554
555
556 #undef YB_Impl_Rational_fp_TmplSig_2_r
557 #undef YB_Impl_Rational_fp_TmplSig_2_l
558 #undef YB_Impl_Rational_fp_TmplSig_2
559 #undef YB_Impl_Rational_fp_TmplBody_Impl_2
560 #undef YB_Impl_Rational_fp_TmplHead_2_r
561 #undef YB_Impl_Rational_fp_TmplHead_2_l
562 #undef YB_Impl_Rational_fp_TmplHead_2
563
565 template<YB_Impl_Rational_fp_PList>
566 yconstfn YB_Impl_Rational_fp_T
567 abs(YB_Impl_Rational_fp_T x) ynothrow
568 {
569 return fabs(x);
570 }
572
573
579 template<YB_Impl_Rational_fp_PList>
580 struct modular_arithmetic<YB_Impl_Rational_fp_T>
581 : modular_arithmetic<typename YB_Impl_Rational_fp_T::base_type>
582 {};
583
584
589 template<YB_Impl_Rational_fp_PList>
590 struct is_normalizable<YB_Impl_Rational_fp_T> : true_type
591 {};
592
593
598 template<size_t _vFrac, size_t _vInt = 1, bool _bSigned = false>
599 using make_fixed_t = fixed_point<conditional_t<_bSigned,
600 typename make_width_int<_vFrac + _vInt>::least_type,
601 typename make_width_int<_vFrac + _vInt>::unsigned_least_type>, _vFrac>;
602
603 } // namespace ystdex;
604
605
606 namespace std
607 {
608
614 template<YB_Impl_Rational_fp_PList1, YB_Impl_Rational_fp_PList2>
615 struct common_type<ystdex::YB_Impl_Rational_fp_T1,
616 ystdex::YB_Impl_Rational_fp_T2>
617 {
618 private:
619 using common_base_type = ystdex::common_type_t<_tBase1, _tBase2>;
620
621 static yconstexpr const size_t int_size = _vInt1 < _vInt2 ? _vInt2 : _vInt1;
622
623 public:
624 using type = ystdex::fixed_point<common_base_type, int_size,
625 std::numeric_limits<common_base_type>::digits - int_size>;
626 };
627
637 template<YB_Impl_Rational_fp_PList, typename _type>
638 struct common_type<ystdex::YB_Impl_Rational_fp_T, _type>
639 {
640 private:
641 using fixed = ystdex::YB_Impl_Rational_fp_T;
642
643 public:
644 using type = ystdex::cond_t<is_floating_point<_type>
645 #if false
646 || !(std::double_t(std::numeric_limits<fixed>::min())
647 < std::double_t(std::numeric_limits<_type>::min())
648 || std::double_t(std::numeric_limits<_type>::max())
649 < std::double_t(std::numeric_limits<fixed>::max()))
650 #endif
651 , _type, fixed>;
652 };
653
654 template<typename _type, YB_Impl_Rational_fp_PList>
655 struct common_type<_type, ystdex::YB_Impl_Rational_fp_T>
656 {
657 using type = ystdex::common_type_t<ystdex::YB_Impl_Rational_fp_T, _type>;
658 };
660
661
667 template<typename>
668 struct hash;
669
670 template<YB_Impl_Rational_fp_PList>
671 struct hash<ystdex::YB_Impl_Rational_fp_T>
672 {
673 size_t
674 operator()(const ystdex::YB_Impl_Rational_fp_T& k) const
675 ynoexcept_spec(yimpl(hash<_tBase>{}(k.get())))
676 {
677 return hash<_tBase>{}(k.get());
678 }
679 };
681
682
689 template<YB_Impl_Rational_fp_PList>
690 class numeric_limits<ystdex::YB_Impl_Rational_fp_T>
691 {
692 private:
693 using fp_type = ystdex::YB_Impl_Rational_fp_T;
694 using base_type = typename fp_type::base_type;
695
696 public:
697 static yconstexpr const bool is_specialized = true;
698
699 static yconstfn fp_type
700 min() ynothrow
701 {
702 return fp_type(std::numeric_limits<base_type>::min(),
703 ystdex::raw_tag());
704 }
705
706 static yconstfn fp_type
707 max() ynothrow
708 {
709 return fp_type(std::numeric_limits<base_type>::max(),
710 ystdex::raw_tag());
711 }
712
713 static yconstfn fp_type
714 lowest() ynothrow
715 {
716 return min();
717 }
718
719 static yconstexpr const int digits = _vInt;
720 static yconstexpr const int digits10 = digits * 643L / 2136;
721 static yconstexpr const int max_digits10 = 0;
722 static yconstexpr const bool is_signed = numeric_limits<base_type>::is_signed;
723 static yconstexpr const bool is_integer = {};
724 static yconstexpr const bool is_exact = true;
725 static yconstexpr const int radix = 2;
726
727 static yconstfn fp_type
728 epsilon() ynothrow
729 {
730 return fp_type(1, typename ystdex::raw_tag());
731 }
732
733 static yconstfn fp_type
734 round_error() ynothrow
735 {
736 return 0.5;
737 }
738
739 static yconstexpr const int min_exponent = 0;
740 static yconstexpr const int min_exponent10 = 0;
741 static yconstexpr const int max_exponent = 0;
742 static yconstexpr const int max_exponent10 = 0;
743
744 static yconstexpr const bool has_infinity = {};
745 static yconstexpr const bool has_quiet_NaN = {};
746 static yconstexpr const bool has_signaling_NaN = has_quiet_NaN;
747 static yconstexpr const float_denorm_style has_denorm = denorm_absent;
748 static yconstexpr const bool has_denorm_loss = {};
749
750 static yconstfn fp_type
751 infinity() ynothrow
752 {
753 return 0;
754 }
755
756 static yconstfn fp_type
757 quiet_NaN() ynothrow
758 {
759 return 0;
760 }
761
762 static yconstfn fp_type
763 signaling_NaN() ynothrow
764 {
765 return 0;
766 }
767
768 static yconstfn fp_type
769 denorm_min() ynothrow
770 {
771 return 0;
772 }
773
774 static yconstexpr const bool is_iec559 = {};
775 static yconstexpr const bool is_bounded = true;
776 static yconstexpr const bool is_modulo
777 = numeric_limits<base_type>::is_modulo;
778
779 static yconstexpr const bool traps = numeric_limits<base_type>::traps;
780 static yconstexpr const bool tinyness_before = {};
781 static yconstexpr const float_round_style round_style = round_toward_zero;
782 };
783
785
786 template<YB_Impl_Rational_fp_PList>
787 class numeric_limits<const ystdex::YB_Impl_Rational_fp_T>
788 : yimpl(public) numeric_limits<ystdex::YB_Impl_Rational_fp_T>
789 {};
790
791 template<YB_Impl_Rational_fp_PList>
792 class numeric_limits<volatile ystdex::YB_Impl_Rational_fp_T>
793 : yimpl(public) numeric_limits<ystdex::YB_Impl_Rational_fp_T>
794 {};
795
796 template<YB_Impl_Rational_fp_PList>
797 class numeric_limits<const volatile ystdex::YB_Impl_Rational_fp_T>
798 : yimpl(public) numeric_limits<ystdex::YB_Impl_Rational_fp_T>
799 {};
801
802 #undef YB_Impl_Rational_fp_PList2
803 #undef YB_Impl_Rational_fp_PList1
804 #undef YB_Impl_Rational_fp_PList
805 #undef YB_Impl_Rational_fp_T2
806 #undef YB_Impl_Rational_fp_T1
807 #undef YB_Impl_Rational_fp_T
808
809 } // namespace std;
810
811 #endif
812
ystdex::fixed_point::operator!
bool operator!() const
Definition: rational.hpp:288
ystdex::cpp2014::conditional_t
typename conditional< _bCond, _type, _type2 >::type conditional_t
Definition: type_traits.hpp:353
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::quiet_NaN
static fp_type quiet_NaN()
Definition: rational.hpp:757
ystdex::fixed_point::operator-=
fixed_point & operator-=(const fixed_point &f)
Definition: rational.hpp:326
ystdex::fixed_point::fabs
friend fixed_point fabs(fixed_point x)
Definition: rational.hpp:445
YSLib::Drawing::x
The boundary is out of the const Rect SDst SPos x
Definition: YDraw.h:127
ystdex::fixed_point::operator=
fixed_point & operator=(const fixed_point &)=default
cmath.h
标准库实现 修正。
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::min
static fp_type min()
Definition: rational.hpp:700
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::round_error
static fp_type round_error()
Definition: rational.hpp:734
ystdex::is_zero
enable_if_t< is_floating_point< _type >::value, bool > is_zero(_type x)
判断指定的值是否为零值。
Definition: rational.hpp:45
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:619
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
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::lowest
static fp_type lowest()
Definition: rational.hpp:714
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
v
byte v
Definition: CharRenderer.cpp:75
std::hash< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::operator()
size_t operator()(const ystdex::fixed_point< _tBase, _vInt, _vFrac > &k) const
Definition: rational.hpp:674
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_traits.hpp:350
platform::KeyCodes::DS::L
Definition: Keys.h:227
ystdex::fixed_point::operator==
bool operator==(const fixed_point &f) const
Definition: rational.hpp:282
ystdex::fixed_point
通用定点数。
Definition: rational.hpp:163
ystdex::fixed_point::int_bit_n
static const size_t int_bit_n
整数部分二进制位数。
Definition: rational.hpp:179
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::fixed_point
fixed_point(const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &f, enable_if_t<(frac_bit_n< _vOtherFrac), base_type * >={})
Definition: rational.hpp:257
YB_Impl_Rational_fp_T2
#define YB_Impl_Rational_fp_T2
Definition: rational.hpp:134
ystdex::square
_type square(_type x)
计算平方。
Definition: rational.hpp:99
ystdex::fixed_point::fixed_point
fixed_point(_tFloat val, enable_if_t< is_floating_point< _tFloat >::value, _tFloat * >={})
Definition: rational.hpp:212
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:760
ystdex::fixed_point::operator<
bool operator<(const fixed_point &f) const
Definition: rational.hpp:276
ystdex::fixed_point::digit_bit_n
static const size_t digit_bit_n
非符号位的二进制位数。
Definition: rational.hpp:183
ystdex::bool_constant
integral_constant< bool, _b > bool_constant
bool 常量。
Definition: type_traits.hpp:382
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:657
ystdex::fixed_point::floor
friend fixed_point floor(fixed_point x)
Definition: rational.hpp:458
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::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:145
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:256
ystdex::fixed_point::operator--
fixed_point & operator--()
Definition: rational.hpp:312
ystdex::fixed_point::abs
fixed_point< _tBase, _vInt, _vFrac > abs(fixed_point< _tBase, _vInt, _vFrac > x)
Definition: rational.hpp:567
ynoexcept_spec
#define ynoexcept_spec(...)
表达式 noexcept 异常规范。
Definition: ydef.h:768
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::base_type
typename fp_type::base_type base_type
Definition: rational.hpp:694
ystdex::round_in
_type round_in(_type x, _type err)
Definition: rational.hpp:80
ystdex::quad
_type quad(_type x)
计算四次方。
Definition: rational.hpp:115
ystdex::fixed_point::operator-
fixed_point operator-() const
Definition: rational.hpp:294
std
Definition: memory.hpp:1100
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: type_traits.hpp:96
YB_Impl_Rational_fp_T1
#define YB_Impl_Rational_fp_T1
Definition: rational.hpp:133
ystdex::fixed_point::operator>>=
fixed_point & operator>>=(size_t s)
Definition: rational.hpp:353
ystdex::fixed_point::fixed_point
fixed_point()=default
无参数构造。
ystdex::fixed_point::operator+=
fixed_point & operator+=(const fixed_point &f)
Definition: rational.hpp:319
std::hash
ystdex::observer_ptr 散列支持。
Definition: memory.hpp:1110
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::denorm_min
static fp_type denorm_min()
Definition: rational.hpp:769
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::max
const _type & max(const _type &a, const _type &b, _fComp comp=less< _type >())
取较大的元素。
Definition: algorithm.hpp:543
ystdex::fixed_point::frac_bit_n
static const size_t frac_bit_n
小数部分二进制位数。
Definition: rational.hpp:181
YB_Impl_Rational_fp_arithmetic2
#define YB_Impl_Rational_fp_arithmetic2(_op)
不同模板参数的二元算术操作符。
Definition: rational.hpp:499
ystdex::cond_t
conditional_t< _tCond::value, _tThen, _tElse > cond_t
条件判断。
Definition: type_traits.hpp:698
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:142
ystdex::fixed_point::operator<<=
fixed_point & operator<<=(size_t s)
Definition: rational.hpp:361
ystdex::raw_tag
直接构造类型（直接构造重载用）。
Definition: ydef.h:909
ystdex::pow_int
_type pow_int(_type x, size_t n)
计算整数次幂。
Definition: rational.hpp:90
ystdex::fixed_point::ceil
friend fixed_point ceil(fixed_point x)
Definition: rational.hpp:451
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex::fixed_point::mul
static base_type mul(base_type x, base_type y, true_type)
Definition: rational.hpp:396
ystdex::fixed_point::value
base_type value
Definition: rational.hpp:186
ystdex::fixed_point::mul
static base_type mul(base_type x, base_type y, false_type)
Definition: rational.hpp:403
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 > >::signaling_NaN
static fp_type signaling_NaN()
Definition: rational.hpp:763
cstdint.hpp
ISO C 标准整数类型和相关扩展操作。
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
std::common_type< ystdex::fixed_point< _tBase, _vInt, _vFrac >, _type >::type
ystdex::cond_t< is_floating_point< _type >, _type, fixed > type
Definition: rational.hpp:651
ystdex::fixed_point< yimpl(std::uint32_t, 12U)>::base_type
yimpl(std::uint32_t, 12U) base_type
Definition: rational.hpp:176
operators.hpp
重载操作符。
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:654
YB_Impl_Rational_fp_rational2
#define YB_Impl_Rational_fp_rational2(_op)
不同模板参数的二元关系操作符。
Definition: rational.hpp:530
ystdex::fixed_point::round
friend fixed_point round(fixed_point x)
Definition: rational.hpp:464
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::max
static fp_type max()
Definition: rational.hpp:707
YB_Impl_Rational_fp_T
#define YB_Impl_Rational_fp_T
Definition: rational.hpp:132
ystdex::make_widen_int::type
typename make_signed_c< typename make_width_int< integer_width< _type >::value<< 1 >::type, _bSigned >::type type
Definition: cstdint.hpp:206
ystdex::fixed_point::operator++
fixed_point & operator++()
Definition: rational.hpp:305
ystdex::is_normalizable
判断类型是否可满足正规化要求：在 0 和 1 之间存在值进行表示。
Definition: rational.hpp:128
ystdex::min
const _type & min(const _type &a, const _type &b, _fComp comp=less< _type >())
取较小的元素。
Definition: algorithm.hpp:521
ystdex::or_
Definition: type_traits.hpp:412
ystdex::make_widen_int
位加倍扩展。
Definition: cstdint.hpp:203
ystdex::modular_arithmetic
模算术特性：取得不超过模值的最大值。
Definition: cstdint.hpp:232
ystdex::fixed_point::identity
static fixed_point identity()
取单位元。
Definition: rational.hpp:439
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430
ystdex::cube
_type cube(_type x)
计算立方。
Definition: rational.hpp:107
ystdex::fixed_point::operator/=
fixed_point & operator/=(const fixed_point &f)
Definition: rational.hpp:342
ystdex::fixed_point::base_element
static base_type base_element()
取 base_type 表达的单位元。
Definition: rational.hpp:428
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::infinity
static fp_type infinity()
Definition: rational.hpp:751
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
ystdex::and_
逻辑操作元函数。
Definition: type_traits.hpp:394
ystdex::fixed_point::fixed_point
fixed_point(base_type v, raw_tag)
Definition: rational.hpp:196
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
ystdex::dep_ops::operators
details::flat_ops< _type, _type2, _tOpt, totally_ordered, integer_arithmetic, bitwise > operators
Definition: operators.hpp:450
ystdex::not_
Definition: type_traits.hpp:430
ystdex::fixed_point::fixed_point
fixed_point(_tInt val, enable_if_t< is_integral< _tInt >::value, _tInt * >={})
Definition: rational.hpp:202
ystdex::fixed_point::operator*=
fixed_point & operator*=(const fixed_point &f)
Definition: rational.hpp:333
ystdex::fixed_point::mul_signed
static base_type mul_signed(_t< make_widen_int< base_type >> tmp)
Definition: rational.hpp:416
std::numeric_limits< ystdex::fixed_point< _tBase, _vInt, _vFrac > >::epsilon
static fp_type epsilon()
Definition: rational.hpp:728
platform::n
size_t n
Definition: YCLib/FileSystem.cpp:321