Embedded Template Library 1.0
Loading...
Searching...
No Matches
duration.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2023 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_IN_CHRONO_H
32 #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
33#endif
34
35#include "../../ratio.h"
36#include "../../static_assert.h"
37#include "../../limits.h"
38#include "../../type_traits.h"
39
40#include <string.h>
41
42namespace etl
43{
44 namespace chrono
45 {
46 namespace private_chrono
47 {
48 // Helper to find the greatest common divisor
49 template <intmax_t Value1, intmax_t Value2>
50 struct gcd
51 {
52 static ETL_CONSTANT intmax_t value = gcd<Value2, Value1 % Value2>::value;
53 };
54
55 template <intmax_t Value1>
56 struct gcd<Value1, 0>
57 {
58 static ETL_CONSTANT intmax_t value = Value1;
59 };
60
61 // Helper to find the least common multiple
62 template <intmax_t Value1, intmax_t Value2>
63 struct lcm
64 {
65 static ETL_CONSTANT intmax_t value = (Value1 / gcd<Value1, Value2>::value) * Value2;
66 };
67 }
68
69 //***********************************************************************
71 //***********************************************************************
72 template <typename TRep>
74 {
75 //***********************************************************************
76 ETL_NODISCARD
77 static ETL_CONSTEXPR TRep zero() ETL_NOEXCEPT
78 {
79 return TRep(0);
80 }
81
82 //***********************************************************************
83 ETL_NODISCARD
84 static ETL_CONSTEXPR14 TRep min() ETL_NOEXCEPT
85 {
87 }
88
89 //***********************************************************************
90 ETL_NODISCARD
91 static ETL_CONSTEXPR14 TRep max() ETL_NOEXCEPT
92 {
94 }
95 };
96
97 template <typename TRep, typename TPeriod>
98 class duration;
99
100 template <typename TToDuration, typename TRep, typename TPeriod>
101 ETL_CONSTEXPR14 TToDuration duration_cast(const etl::chrono::duration<TRep, TPeriod>& d) ETL_NOEXCEPT;
102
103 //***********************************************************************
105 //***********************************************************************
106 template <typename TRep, typename TPeriod = etl::ratio<1> >
107 class duration
108 {
109 public:
110
111 using rep = TRep;
112 using period = typename TPeriod::type;
113
114 //***********************************************************************
115 ETL_CONSTEXPR duration() ETL_NOEXCEPT
116 : value(0)
117 {
118 }
119
120 //***********************************************************************
121 ETL_CONSTEXPR14 duration(const etl::chrono::duration<TRep, TPeriod>& other) ETL_NOEXCEPT
122 : value(other.value)
123 {
124 }
125
126 //***********************************************************************
127 template <typename TRep2>
128 ETL_CONSTEXPR14 explicit duration(const TRep2& value_) ETL_NOEXCEPT
129 : value(static_cast<TRep>(value_))
130 {
131 }
132
133 //***********************************************************************
134 template <typename TRep2, typename TPeriod2, typename etl::enable_if<etl::ratio_divide<TPeriod2, TPeriod>::den == 1, int>::type = 0>
135 ETL_CONSTEXPR14 duration(const etl::chrono::duration<TRep2, TPeriod2>& other) ETL_NOEXCEPT
137 {
138 ETL_STATIC_ASSERT(!(etl::is_integral<TRep>::value && etl::is_floating_point<TRep2>::value), "Cannot convert duration from floating point to integral");
139 }
140
141 //***********************************************************************
142 ETL_CONSTEXPR14
144 {
145 value = other.count();
146
147 return *this;
148 }
149
150 //***********************************************************************
151 template <typename TRep2, typename TPeriod2>
152 ETL_CONSTEXPR14
154 {
156
157 return *this;
158 }
159
160 //***********************************************************************
161 ETL_CONSTEXPR14 TRep count() const ETL_NOEXCEPT
162 {
163 return value;
164 }
165
166 //***********************************************************************
167 ETL_CONSTEXPR14 etl::common_type_t<duration> operator +() const ETL_NOEXCEPT
168 {
169 return etl::common_type_t<duration>(*this);
170 }
171
172 //***********************************************************************
173 ETL_CONSTEXPR14 etl::common_type_t<duration> operator -() const ETL_NOEXCEPT
174 {
175 return etl::common_type_t<duration>(-value);
176 }
177
178 //***********************************************************************
179 ETL_NODISCARD
180 static ETL_CONSTEXPR14 etl::chrono::duration<TRep, TPeriod> zero() ETL_NOEXCEPT
181 {
182 return etl::chrono::duration<TRep, TPeriod>(etl::chrono::duration_values<TRep>::zero());
183 }
184
185 //***********************************************************************
186 ETL_NODISCARD
187 static ETL_CONSTEXPR14 etl::chrono::duration<TRep, TPeriod> min() ETL_NOEXCEPT
188 {
189 return etl::chrono::duration<TRep, TPeriod>(etl::chrono::duration_values<TRep>::min());
190 }
191
192 //***********************************************************************
193 ETL_NODISCARD
194 static ETL_CONSTEXPR14 etl::chrono::duration<TRep, TPeriod> max() ETL_NOEXCEPT
195 {
196 return etl::chrono::duration<TRep, TPeriod>(etl::chrono::duration_values<TRep>::max());
197 }
198
199 //***********************************************************************
200 ETL_NODISCARD
201 ETL_CONSTEXPR14 etl::chrono::duration<TRep, TPeriod> absolute() const ETL_NOEXCEPT
202 {
203 return etl::chrono::duration<TRep, TPeriod>(value < 0 ? -value : value);
204 }
205
206 //***********************************************************************
207 ETL_CONSTEXPR14 duration& operator ++() ETL_NOEXCEPT
208 {
209 ++value;
210
211 return *this;
212 }
213
214 //***********************************************************************
215 ETL_CONSTEXPR14 duration operator ++(int) ETL_NOEXCEPT
216 {
217 duration temp(*this);
218 ++value;
219
220 return temp;
221 }
222
223 //***********************************************************************
224 ETL_CONSTEXPR14 duration& operator --() ETL_NOEXCEPT
225 {
226 --value;
227
228 return *this;
229 }
230
231 //***********************************************************************
232 ETL_CONSTEXPR14 duration operator --(int) ETL_NOEXCEPT
233 {
234 duration temp(*this);
235 --value;
236
237 return temp;
238 }
239
240 //***********************************************************************
241 ETL_CONSTEXPR14 duration& operator +=(const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
242 {
243 value += d.count();
244
245 return *this;
246 }
247
248 //***********************************************************************
249 ETL_CONSTEXPR14 duration& operator -=(const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
250 {
251 value -= d.count();
252
253 return *this;
254 }
255
256 //***********************************************************************
257 ETL_CONSTEXPR14 duration& operator *=(const TRep& r) ETL_NOEXCEPT
258 {
259 value *= r;
260
261 return *this;
262 }
263
264 //***********************************************************************
265 ETL_CONSTEXPR14 duration& operator /=(const TRep& r) ETL_NOEXCEPT
266 {
267 value /= r;
268
269 return *this;
270 }
271
272 //***********************************************************************
273 ETL_CONSTEXPR14 duration& operator %=(const TRep& r) ETL_NOEXCEPT
274 {
275 value %= r;
276
277 return *this;
278 }
279
280 //***********************************************************************
281 ETL_CONSTEXPR14 duration& operator %=(const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
282 {
283 value %= d.count();
284
285 return *this;
286 }
287
288 //***********************************************************************
293 //***********************************************************************
294 template <typename TRep2, typename TPeriod2>
295 ETL_CONSTEXPR14 int compare(const duration<TRep2, TPeriod2>& other) const ETL_NOEXCEPT
296 {
297 // Determine the common type of the two durations.
298 using common_duration = typename etl::common_type<etl::chrono::duration<TRep, TPeriod>, etl::chrono::duration<TRep2, TPeriod2>>::type;
299
300 common_duration lhs_converted = etl::chrono::duration_cast<common_duration>(*this);
301 common_duration rhs_converted = etl::chrono::duration_cast<common_duration>(other);
302
303 if (lhs_converted.count() < rhs_converted.count()) return -1;
304 if (lhs_converted.count() > rhs_converted.count()) return 1;
305
306 return 0;
307 }
308
309 private:
310
311 TRep value;
312 };
313
314 //***********************************************************************
316 //***********************************************************************
317#if (ETL_USING_64BIT_TYPES)
322#else
327#endif
334
335 //***********************************************************************
337 //***********************************************************************
338 template <typename TToDuration, typename TRep, typename TPeriod>
339 ETL_CONSTEXPR14 TToDuration duration_cast(const etl::chrono::duration<TRep, TPeriod>& d) ETL_NOEXCEPT
340 {
341 using from_rep = TRep ;
342 using from_period = TPeriod ;
343
344 using to_rep = typename TToDuration::rep;
345 using to_period = typename TToDuration::period;
346
347 using ratio_divide_t = typename etl::ratio_divide<from_period, to_period>;
348 using common_t = typename etl::common_type<from_rep, to_rep, intmax_t>::type;
349
350 common_t ct_count = static_cast<common_t>(d.count());
351 common_t ct_num = static_cast<common_t>(ratio_divide_t::type::num);
352 common_t ct_den = static_cast<common_t>(ratio_divide_t::type::den);
353
354 if ETL_IF_CONSTEXPR((from_period::num == to_period::num) && (from_period::den == to_period::den))
355 {
356 return TToDuration(static_cast<to_rep>(d.count()));
357 }
358 else if ETL_IF_CONSTEXPR(ratio_divide_t::num == 1)
359 {
360 return TToDuration(static_cast<to_rep>(ct_count / ct_den));
361 }
362 else if ETL_IF_CONSTEXPR(ratio_divide_t::den == 1)
363 {
364 return TToDuration(static_cast<to_rep>(ct_count * ct_num));
365 }
366 else
367 {
368 return TToDuration(static_cast<to_rep>((ct_count * ct_num) / ct_den));
369 }
370 }
371 }
372
373 //*************************************************************************
375 //*************************************************************************
376#if ETL_USING_8BIT_TYPES
377 template <typename TRep, typename TPeriod>
378 struct hash<etl::chrono::duration<TRep, TPeriod> >
379 {
380 ETL_CONSTEXPR14 size_t operator()(const etl::chrono::duration<TRep, TPeriod>& d) const ETL_NOEXCEPT
381 {
382 uint8_t buffer[sizeof(TRep) + sizeof(intmax_t) + sizeof(intmax_t)];
383
384 TRep value = d.count();
385 intmax_t num = TPeriod::num;
386 intmax_t den = TPeriod::den;
387
388 memcpy(buffer, &value, sizeof(TRep));
389 memcpy(buffer + sizeof(TRep), &num, sizeof(intmax_t));
390 memcpy(buffer + sizeof(TRep) + sizeof(intmax_t), &den, sizeof(intmax_t));
391
392 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(TRep) + sizeof(intmax_t) + sizeof(intmax_t));
393 }
394 };
395#endif
396
397 //***********************************************************************
399 //***********************************************************************
400 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
401 struct common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2>>
402 {
403 private:
404
405 using value_type = typename etl::common_type<TRep1, TRep2>::type ;
407 etl::chrono::private_chrono::lcm<TPeriod1::den, TPeriod2::den>::value>;
408
409 public:
410
412 };
413
414 //***********************************************************************
416 //***********************************************************************
417 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
418 ETL_CONSTEXPR14 bool operator ==(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
419 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
420 {
421 using common_t = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2> >::type;
422
423 common_t l = etl::chrono::duration_cast<common_t>(lhs);
424 common_t r = etl::chrono::duration_cast<common_t>(rhs);
425
426 return l.count() == r.count();
427 }
428
429 //***********************************************************************
431 //***********************************************************************
432 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
433 ETL_CONSTEXPR14 bool operator !=(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
434 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
435 {
436 return !(lhs == rhs);
437 }
438
439 //***********************************************************************
441 //***********************************************************************
442 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
443 ETL_CONSTEXPR14 bool operator <(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
444 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
445 {
446 using common_t = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2> >::type;
447
448 common_t l = etl::chrono::duration_cast<common_t>(lhs);
449 common_t r = etl::chrono::duration_cast<common_t>(rhs);
450
451 return l.count() < r.count();
452 }
453
454 //***********************************************************************
456 //***********************************************************************
457 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
458 ETL_CONSTEXPR14 bool operator <=(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
459 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
460 {
461 return !(rhs < lhs);
462 }
463
464 //***********************************************************************
466 //***********************************************************************
467 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
468 ETL_CONSTEXPR14 bool operator >(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
469 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
470 {
471 return rhs < lhs;
472 }
473
474 //***********************************************************************
476 //***********************************************************************
477 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
478 ETL_CONSTEXPR14 bool operator >=(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
479 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
480 {
481 return !(lhs < rhs);
482 }
483
484 //***********************************************************************
486 //***********************************************************************
487#if ETL_USING_CPP20
488 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
489 [[nodiscard]] constexpr auto operator <=>(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
490 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
491 {
492 using common_t = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2> >::type;
493
494 common_t l = etl::chrono::duration_cast<common_t>(lhs);
495 common_t r = etl::chrono::duration_cast<common_t>(rhs);
496
497 return (l.count() <=> r.count());
498 }
499#endif
500
501 //***********************************************************************
503 //***********************************************************************
504 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
505 ETL_CONSTEXPR14 typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2> >::type
507 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
508 {
509 // Determine the common type of the two durations.
510 using common_duration = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2>>::type;
511
512 // Convert both durations to the common type.
513 common_duration lhs_converted = etl::chrono::duration_cast<common_duration>(lhs);
514 common_duration rhs_converted = etl::chrono::duration_cast<common_duration>(rhs);
515
516 // Return the sum of the two converted durations.
517 return common_duration(lhs_converted.count() + rhs_converted.count());
518 }
519
520 //***********************************************************************
522 //***********************************************************************
523 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
524 ETL_CONSTEXPR14 typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2> >::type
526 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
527 {
528 // Determine the common type of the two durations.
529 using common_duration = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2>>::type;
530
531 // Convert both durations to the common type.
532 common_duration lhs_converted = etl::chrono::duration_cast<common_duration>(lhs);
533 common_duration rhs_converted = etl::chrono::duration_cast<common_duration>(rhs);
534
535 // Return the difference of the two converted durations.
536 return common_duration(lhs_converted.count() - rhs_converted.count());
537 }
538
539 //***********************************************************************
541 //***********************************************************************
542 template <typename TRep1, typename TPeriod1, typename TRep2>
543 ETL_CONSTEXPR14
544 typename enable_if<!etl::is_specialization<TRep2, etl::chrono::duration>::value, etl::chrono::duration<typename etl::common_type<TRep1, TRep2>::type, TPeriod1>>::type
546 const TRep2& rhs) ETL_NOEXCEPT
547 {
548 using common_rep = typename etl::common_type<TRep1, TRep2>::type;
549 using result_duration = etl::chrono::duration<common_rep, TPeriod1>;
550
551 // Multiply the count of the duration by the scalar value
552 return result_duration(static_cast<common_rep>(lhs.count()) * static_cast<common_rep>(rhs));
553 }
554
555 //***********************************************************************
557 //***********************************************************************
558 template <typename TRep1, typename TRep2, typename TPeriod2>
560 operator *(const TRep1& lhs,
561 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
562 {
563 using common_rep = typename etl::common_type<TRep1, TRep2>::type;
564 using result_duration = etl::chrono::duration<common_rep, TPeriod2>;
565
566 // Multiply the count of the duration by the scalar value
567 return result_duration(static_cast<common_rep>(rhs.count()) * static_cast<common_rep>(lhs));
568 }
569
570 //***********************************************************************
572 //***********************************************************************
573 template <typename TRep1, typename TPeriod1, typename TRep2>
574 ETL_CONSTEXPR14
575 typename enable_if<!etl::is_specialization<TRep2, etl::chrono::duration>::value, etl::chrono::duration<typename etl::common_type<TRep1, TRep2>::type, TPeriod1>>::type
577 const TRep2& rhs) ETL_NOEXCEPT
578 {
579 using common_rep = typename etl::common_type<TRep1, TRep2>::type;
580 using result_duration = etl::chrono::duration<common_rep, TPeriod1>;
581
582 // Divide the count of the duration by the scalar value
583 return result_duration(static_cast<common_rep>(lhs.count()) / static_cast<common_rep>(rhs));
584 }
585
586 //***********************************************************************
588 //***********************************************************************
589 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
590 ETL_CONSTEXPR14 typename etl::common_type<TRep1, TRep2>::type
592 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
593 {
594 // Determine the common type of the two durations.
595 using common_duration = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2>>::type;
596
597 common_duration lhs_converted = etl::chrono::duration_cast<common_duration>(lhs);
598 common_duration rhs_converted = etl::chrono::duration_cast<common_duration>(rhs);
599
600 return typename etl::common_type<TRep1, TRep2>::type(lhs_converted.count() / rhs_converted.count());
601 }
602
603 //***********************************************************************
605 //***********************************************************************
606 template <typename TRep1, typename TPeriod1, typename TRep2>
607 ETL_CONSTEXPR14
610 const TRep2& rhs) ETL_NOEXCEPT
611 {
612 using common_rep = typename etl::common_type<TRep1, TRep2>::type;
614
615 // Mod the count of the duration by the scalar value
616 return common_dur(static_cast<common_rep>(lhs.count()) % rhs);
617 }
618
619 //***********************************************************************
621 //***********************************************************************
622 template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
623 ETL_CONSTEXPR14
624 typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2>>::type
626 const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
627 {
628 // Determine the common type of the two durations.
629 using common_duration = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2>>::type;
630
631 common_duration lhs_converted = etl::chrono::duration_cast<common_duration>(lhs);
632 common_duration rhs_converted = etl::chrono::duration_cast<common_duration>(rhs);
633
634 return common_duration(lhs_converted.count() % rhs_converted.count());
635 }
636
637 //***********************************************************************
639 //***********************************************************************
640 template <typename TToDuration, typename TRep, typename TPeriod>
641 ETL_CONSTEXPR14
644 {
645 TToDuration result = etl::chrono::duration_cast<TToDuration>(d);
646
647 if (result > d)
648 {
649 --result;
650 }
651
652 return result;
653 }
654
655 //***********************************************************************
657 //***********************************************************************
658 template <typename TToDuration, typename TRep, typename TPeriod>
659 ETL_CONSTEXPR14
662 {
663 TToDuration result = etl::chrono::duration_cast<TToDuration>(d);
664
665 if (result < d)
666 {
667 ++result;
668 }
669
670 return result;
671 }
672
673 //***********************************************************************
676 //***********************************************************************
677 template <typename TToDuration, typename TRep, typename TPeriod>
678 ETL_CONSTEXPR14
681 {
682 // Convert the input duration to the target duration type
683 TToDuration lower = floor<TToDuration>(d);
684 TToDuration upper = ceil<TToDuration>(lower + TToDuration(1));
685
686 auto lower_diff = d - lower;
687 auto upper_diff = upper - d;
688
689 if ((lower_diff < upper_diff) ||
690 ((lower_diff == upper_diff) &&
691 etl::is_even(lower.count())))
692 {
693 return lower;
694 }
695 else
696 {
697 return upper;
698 }
699 }
700
701 //***********************************************************************
703 //***********************************************************************
704 template<class TRep, class TPeriod, typename = etl::enable_if_t<etl::numeric_limits<TRep>::is_signed>>
706 {
707 return d.count() >= 0 ? +d : -d;
708 }
709}
710
711#if ETL_HAS_CHRONO_LITERALS_DURATION
712namespace etl
713{
714 inline namespace literals
715 {
716 inline namespace chrono_literals
717 {
718 //***********************************************************************
720 //***********************************************************************
721#if ETL_USING_VERBOSE_CHRONO_LITERALS
722 inline ETL_CONSTEXPR14 etl::chrono::hours operator ""_hours(unsigned long long h) ETL_NOEXCEPT
723#else
724 inline ETL_CONSTEXPR14 etl::chrono::hours operator ""_h(unsigned long long h) ETL_NOEXCEPT
725#endif
726 {
727 return etl::chrono::hours(static_cast<etl::chrono::hours::rep>(h));
728 }
729
730 //***********************************************************************
732 //***********************************************************************
733#if ETL_USING_VERBOSE_CHRONO_LITERALS
734 inline ETL_CONSTEXPR14 etl::chrono::duration<double, ratio<3600>> operator""_hours(long double h) ETL_NOEXCEPT
735#else
736 inline ETL_CONSTEXPR14 etl::chrono::duration<double, ratio<3600>> operator""_h(long double h) ETL_NOEXCEPT
737#endif
738 {
740 }
741
742 //***********************************************************************
744 //***********************************************************************
745#if ETL_USING_VERBOSE_CHRONO_LITERALS
746 inline ETL_CONSTEXPR14 etl::chrono::minutes operator ""_minutes(unsigned long long m) ETL_NOEXCEPT
747#else
748 inline ETL_CONSTEXPR14 etl::chrono::minutes operator ""_min(unsigned long long m) ETL_NOEXCEPT
749#endif
750 {
751 return etl::chrono::minutes(static_cast<etl::chrono::minutes::rep>(m));
752 }
753
754 //***********************************************************************
756 //***********************************************************************
757#if ETL_USING_VERBOSE_CHRONO_LITERALS
758 inline ETL_CONSTEXPR14 etl::chrono::duration<double, ratio<60>> operator ""_minutes(long double m) ETL_NOEXCEPT
759#else
760 inline ETL_CONSTEXPR14 etl::chrono::duration<double, ratio<60>> operator ""_min(long double m) ETL_NOEXCEPT
761#endif
762 {
764 }
765
766 //***********************************************************************
768 //***********************************************************************
769#if ETL_USING_VERBOSE_CHRONO_LITERALS
770 inline ETL_CONSTEXPR14 etl::chrono::seconds operator ""_seconds(unsigned long long s) ETL_NOEXCEPT
771#else
772 inline ETL_CONSTEXPR14 etl::chrono::seconds operator ""_s(unsigned long long s) ETL_NOEXCEPT
773#endif
774 {
775 return etl::chrono::seconds(static_cast<etl::chrono::seconds::rep>(s));
776 }
777
778 //***********************************************************************
780 //***********************************************************************
781#if ETL_USING_VERBOSE_CHRONO_LITERALS
782 inline ETL_CONSTEXPR14 etl::chrono::duration<double> operator ""_seconds(long double s) ETL_NOEXCEPT
783#else
784 inline ETL_CONSTEXPR14 etl::chrono::duration<double> operator ""_s(long double s) ETL_NOEXCEPT
785#endif
786 {
788 }
789
790 //***********************************************************************
792 //***********************************************************************
793#if ETL_USING_VERBOSE_CHRONO_LITERALS
794 inline ETL_CONSTEXPR14 etl::chrono::milliseconds operator ""_milliseconds(unsigned long long s) ETL_NOEXCEPT
795#else
796 inline ETL_CONSTEXPR14 etl::chrono::milliseconds operator ""_ms(unsigned long long s) ETL_NOEXCEPT
797#endif
798 {
799 return etl::chrono::milliseconds(static_cast<etl::chrono::milliseconds::rep>(s));
800 }
801
802 //***********************************************************************
804 //***********************************************************************
805#if ETL_USING_VERBOSE_CHRONO_LITERALS
806 inline ETL_CONSTEXPR14 etl::chrono::duration<double, milli> operator ""_milliseconds(long double s) ETL_NOEXCEPT
807#else
808 inline ETL_CONSTEXPR14 etl::chrono::duration<double, milli> operator ""_ms(long double s) ETL_NOEXCEPT
809#endif
810 {
812 }
813
814 //***********************************************************************
816 //***********************************************************************
817#if ETL_USING_VERBOSE_CHRONO_LITERALS
818 inline ETL_CONSTEXPR14 etl::chrono::microseconds operator ""_microseconds(unsigned long long s) ETL_NOEXCEPT
819#else
820 inline ETL_CONSTEXPR14 etl::chrono::microseconds operator ""_us(unsigned long long s) ETL_NOEXCEPT
821#endif
822 {
823 return etl::chrono::microseconds(static_cast<etl::chrono::microseconds::rep>(s));
824 }
825
826 //***********************************************************************
828 //***********************************************************************
829#if ETL_USING_VERBOSE_CHRONO_LITERALS
830 inline ETL_CONSTEXPR14 etl::chrono::duration<double, micro> operator ""_microseconds(long double s) ETL_NOEXCEPT
831#else
832 inline ETL_CONSTEXPR14 etl::chrono::duration<double, micro> operator ""_us(long double s) ETL_NOEXCEPT
833#endif
834 {
836 }
837
838 //***********************************************************************
840 //***********************************************************************
841#if ETL_USING_VERBOSE_CHRONO_LITERALS
842 inline ETL_CONSTEXPR14 etl::chrono::nanoseconds operator ""_nanoseconds(unsigned long long s) ETL_NOEXCEPT
843#else
844 inline ETL_CONSTEXPR14 etl::chrono::nanoseconds operator ""_ns(unsigned long long s) ETL_NOEXCEPT
845#endif
846 {
847 return etl::chrono::nanoseconds(static_cast<etl::chrono::nanoseconds::rep>(s));
848 }
849
850 //***********************************************************************
852 //***********************************************************************
853#if ETL_USING_VERBOSE_CHRONO_LITERALS
854 inline ETL_CONSTEXPR14 etl::chrono::duration<double, nano> operator ""_nanoseconds(long double s) ETL_NOEXCEPT
855#else
856 inline ETL_CONSTEXPR14 etl::chrono::duration<double, nano> operator ""_ns(long double s) ETL_NOEXCEPT
857#endif
858 {
860 }
861 }
862 }
863}
864#endif
duration
Definition duration.h:108
ETL_CONSTEXPR14 int compare(const duration< TRep2, TPeriod2 > &other) const ETL_NOEXCEPT
Definition duration.h:295
Definition limits.h:1176
etl::chrono::duration< int64_t, etl::nano > nanoseconds
Duration types.
Definition duration.h:318
ETL_CONSTEXPR14 TToDuration duration_cast(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
duration_cast
Definition duration.h:339
ETL_CONSTEXPR etl::enable_if< etl::is_integral< T >::value, bool >::type is_even(T value)
Definition binary.h:2209
enable_if
Definition type_traits_generator.h:1254
is_floating_point
Definition type_traits_generator.h:1094
bitset_ext
Definition absolute.h:39
ETL_CONSTEXPR14 etl::enable_if< etl::is_specialization< TToDuration, etl::chrono::duration >::value, TToDuration >::type ceil(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
Rounds up a duration to the nearest higher precision.
Definition duration.h:661
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator-(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition circular_iterator.h:672
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1190
ETL_CONSTEXPR14 enable_if<!etl::is_specialization< TRep2, etl::chrono::duration >::value, etl::chrono::duration< typenameetl::common_type< TRep1, TRep2 >::type, TPeriod1 > >::type operator/(const etl::chrono::duration< TRep1, TPeriod1 > &lhs, const TRep2 &rhs) ETL_NOEXCEPT
Operator /.
Definition duration.h:576
ETL_CONSTEXPR14 etl::chrono::duration< typename etl::common_type< TRep1, TRep2 >::type, TPeriod1 > operator%(const etl::chrono::duration< TRep1, TPeriod1 > &lhs, const TRep2 &rhs) ETL_NOEXCEPT
Operator %.
Definition duration.h:609
ETL_CONSTEXPR14 etl::chrono::duration< TRep, TPeriod > abs(etl::chrono::duration< TRep, TPeriod > d) ETL_NOEXCEPT
Returns the absolute value of a duration.
Definition duration.h:705
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1202
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
ETL_CONSTEXPR14 etl::enable_if< etl::is_specialization< TToDuration, etl::chrono::duration >::value, TToDuration >::type floor(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
Rounds down a duration to the nearest lower precision.
Definition duration.h:643
ETL_CONSTEXPR14 etl::enable_if< etl::is_specialization< TToDuration, etl::chrono::duration >::value, TToDuration >::type round(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
Definition duration.h:680
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
ETL_CONSTEXPR14 enable_if<!etl::is_specialization< TRep2, etl::chrono::duration >::value, etl::chrono::duration< typenameetl::common_type< TRep1, TRep2 >::type, TPeriod1 > >::type operator*(const etl::chrono::duration< TRep1, TPeriod1 > &lhs, const TRep2 &rhs) ETL_NOEXCEPT
Operator *.
Definition duration.h:545
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator+(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition circular_iterator.h:659
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1163
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1178
duration_values
Definition duration.h:74
Definition duration.h:51
Definition duration.h:64
ratio
Definition ratio.h:53