Embedded Template Library 1.0
Loading...
Searching...
No Matches
to_arithmetic.h
Go to the documentation of this file.
1
2/******************************************************************************
3The MIT License(MIT)
4
5Embedded Template Library.
6https://github.com/ETLCPP/etl
7https://www.etlcpp.com
8
9Copyright(c) 2022 John Wellbelove
10
11Permission is hereby granted, free of charge, to any person obtaining a copy
12of this software and associated documentation files(the "Software"), to deal
13in the Software without restriction, including without limitation the rights
14to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
15copies of the Software, and to permit persons to whom the Software is
16furnished to do so, subject to the following conditions :
17
18The above copyright notice and this permission notice shall be included in all
19copies or substantial portions of the Software.
20
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
24AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27SOFTWARE.
28******************************************************************************/
29
30#ifndef ETL_TO_ARITHMETIC_INCLUDED
31#define ETL_TO_ARITHMETIC_INCLUDED
32
33#include "platform.h"
34#include "type_traits.h"
35#include "integral_limits.h"
36#include "limits.h"
37#include "string_view.h"
38#include "basic_string.h"
39#include "format_spec.h"
40#include "radix.h"
41#include "string_utilities.h"
42#include "iterator.h"
43#include "bit.h"
44#include "smallest.h"
45#include "absolute.h"
46#include "expected.h"
47#include "math.h"
48
49#include <math.h>
50
51namespace etl
52{
53 //***************************************************************************
55 //***************************************************************************
57 {
58 enum enum_type
59 {
60 Valid,
61 Invalid_Radix,
62 Invalid_Format,
63 Invalid_Float,
64 Signed_To_Unsigned,
65 Overflow
66 };
67
69 ETL_ENUM_TYPE(Valid, "Valid")
70 ETL_ENUM_TYPE(Invalid_Radix, "Invalid Radix")
71 ETL_ENUM_TYPE(Invalid_Format, "Invalid Format")
72 ETL_ENUM_TYPE(Invalid_Float, "Invalid Float")
73 ETL_ENUM_TYPE(Signed_To_Unsigned, "Signed To Unsigned")
74 ETL_ENUM_TYPE(Overflow, "Overflow")
75 ETL_END_ENUM_TYPE
76 };
77
78 //***************************************************************************
80 //***************************************************************************
81 template<typename TValue>
83 {
84 public:
85
86 typedef TValue value_type;
87 typedef etl::to_arithmetic_status error_type;
88 typedef etl::unexpected<etl::to_arithmetic_status> unexpected_type;
89
90 //*******************************************
92 //*******************************************
93 ETL_CONSTEXPR14
95 : conversion_value(static_cast<value_type>(0))
96 , conversion_status(error_type::Valid)
97 {
98 }
99
100 //*******************************************
102 //*******************************************
103 ETL_CONSTEXPR14
105 : conversion_value(other.conversion_value)
106 , conversion_status(other.conversion_status)
107 {
108 }
109
110 //*******************************************
112 //*******************************************
113 ETL_NODISCARD
114 ETL_CONSTEXPR14
115 bool has_value() const
116 {
117 return (conversion_status.error() == error_type::Valid);
118 }
119
120 //*******************************************
122 //*******************************************
123 ETL_NODISCARD
124 ETL_CONSTEXPR14
125 operator bool() const
126 {
127 return has_value();
128 }
129
130 //*******************************************
133 //*******************************************
134 ETL_NODISCARD
135 ETL_CONSTEXPR14
136 value_type value() const
137 {
138 return conversion_value;
139 }
140
141 //*******************************************
144 //*******************************************
145 ETL_NODISCARD
146 ETL_CONSTEXPR14
147 operator value_type() const
148 {
149 return value();
150 }
151
152 //*******************************************
161 //*******************************************
162 ETL_NODISCARD
163 ETL_CONSTEXPR14
164 error_type error() const
165 {
166 return etl::to_arithmetic_status(conversion_status.error());
167 }
168
169 //*******************************************
171 //*******************************************
172 ETL_CONSTEXPR14
174 {
175 conversion_value = value_;
176
177 return *this;
178 }
179
180 //*******************************************
182 //*******************************************
183 ETL_CONSTEXPR14
184 to_arithmetic_result& operator =(unexpected_type status_)
185 {
186 conversion_status = status_;
187
188 return *this;
189 }
190
191 private:
192
193 value_type conversion_value;
194 unexpected_type conversion_status;
195 };
196
197 namespace private_to_arithmetic
198 {
199 template <typename T = void>
201 {
202 static ETL_CONSTANT char Positive_Char = '+';
203 static ETL_CONSTANT char Negative_Char = '-';
204 static ETL_CONSTANT char Radix_Point1_Char = '.';
205 static ETL_CONSTANT char Radix_Point2_Char = ',';
206 static ETL_CONSTANT char Exponential_Char = 'e';
207 };
208
209 template <typename T>
210 ETL_CONSTANT char char_statics<T>::Positive_Char;
211
212 template <typename T>
213 ETL_CONSTANT char char_statics<T>::Negative_Char;
214
215 template <typename T>
216 ETL_CONSTANT char char_statics<T>::Radix_Point1_Char;
217
218 template <typename T>
219 ETL_CONSTANT char char_statics<T>::Radix_Point2_Char;
220
221 template <typename T>
222 ETL_CONSTANT char char_statics<T>::Exponential_Char;
223
225 {
226 };
227
228 //*******************************************
229 ETL_NODISCARD
230 inline
231 ETL_CONSTEXPR14
232 bool is_valid(char c, etl::radix::value_type radix)
233 {
234 switch (radix)
235 {
236 case etl::radix::binary:
237 {
238 return (c >= '0') && (c <= '1');
239 }
240
241 case etl::radix::octal:
242 {
243 return (c >= '0') && (c <= '7');
244 }
245
246 case etl::radix::decimal:
247 {
248 return (c >= '0') && (c <= '9');
249 }
250
251 case etl::radix::hexadecimal:
252 {
253 return ((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f'));
254 }
255
256 default:
257 {
258 return false;
259 }
260 }
261 }
262
263 //*******************************************
264 ETL_NODISCARD
265 inline
266 ETL_CONSTEXPR14
267 char digit_value(char c, etl::radix::value_type radix)
268 {
269 switch (radix)
270 {
271 case etl::radix::binary:
272 case etl::radix::octal:
273 case etl::radix::decimal:
274 {
275 return c - '0';
276 }
277
278 case etl::radix::hexadecimal:
279 {
280 if ((c >= '0') && (c <= '9'))
281 {
282 return c - '0';
283 }
284 else
285 {
286 return (c - 'a') + 10;
287 }
288 }
289
290 default:
291 {
292 return 0;
293 }
294 }
295 }
296
297 //*******************************************
298 ETL_NODISCARD
299 inline
300 ETL_CONSTEXPR14
301 char to_lower(char c)
302 {
303 if ((c >= 'A') && (c <= 'Z'))
304 {
305 c += 32;
306 }
307
308 return c;
309 }
310
311 //*******************************************
312 template <typename TChar>
313 ETL_NODISCARD
314 ETL_CONSTEXPR14
315 char convert(TChar c)
316 {
317 return to_lower(static_cast<char>(c));
318 }
319
320 //***************************************************************************
323 //***************************************************************************
324 template <typename TChar>
325 ETL_NODISCARD
326 ETL_CONSTEXPR14
328 {
329 if (!view.empty())
330 {
331 // Check for prefix.
332 const char c = convert(view[0]);
333 const bool has_positive_prefix = (c == char_constant::Positive_Char);
334 const bool has_negative_prefix = (c == char_constant::Negative_Char);
335
336 // Step over the prefix, if present.
337 if (has_positive_prefix || has_negative_prefix)
338 {
339 view.remove_prefix(1);
340 return has_negative_prefix;
341 }
342 }
343
344 return false;
345 }
346
347 //***************************************************************************
349 //***************************************************************************
350 ETL_NODISCARD
351 inline
352 ETL_CONSTEXPR14
353 bool is_valid_radix(const etl::radix::value_type radix)
354 {
355 return (radix == etl::radix::binary) ||
356 (radix == etl::radix::octal) ||
357 (radix == etl::radix::decimal) ||
358 (radix == etl::radix::hexadecimal);
359 }
360
361 //***************************************************************************
363 //***************************************************************************
364 template <typename TValue>
365 struct integral_accumulator
366 {
367 //*********************************
368 ETL_CONSTEXPR14
369 integral_accumulator(etl::radix::value_type radix_, TValue maximum_)
370 : radix(radix_)
371 , maximum(maximum_)
372 , integral_value(0)
373 , conversion_status(to_arithmetic_status::Valid)
374 {
375 }
376
377 //*********************************
378 ETL_NODISCARD
379 ETL_CONSTEXPR14
380 bool add(const char c)
381 {
382 bool is_success = false;
383 bool is_not_overflow = false;
384
385 const bool is_valid_char = is_valid(c, radix);
386
387 if (is_valid_char)
388 {
389 TValue old_value = integral_value;
390 integral_value *= radix;
391
392 // No multiplication overflow?
393 is_not_overflow = ((integral_value / radix) == old_value);
394
395 if (is_not_overflow)
396 {
397 const char digit = digit_value(c, radix);
398
399 // No addition overflow?
400 is_not_overflow = ((maximum - digit) >= integral_value);
401
402 if ((maximum - digit) >= integral_value)
403 {
404 integral_value += digit;
405 is_success = true;
406 }
407 }
408 }
409
410 // Check the status of the conversion.
411 if (is_valid_char == false)
412 {
413 conversion_status = to_arithmetic_status::Invalid_Format;
414 }
415 else if (is_not_overflow == false)
416 {
417 conversion_status = to_arithmetic_status::Overflow;
418 }
419
420 return is_success;
421 }
422
423 //*********************************
424 ETL_NODISCARD
425 ETL_CONSTEXPR14
426 bool has_value() const
427 {
428 return conversion_status == to_arithmetic_status::Valid;
429 }
430
431 //*********************************
432 ETL_NODISCARD
433 ETL_CONSTEXPR14
434 TValue value() const
435 {
436 return integral_value;
437 }
438
439 //*********************************
440 ETL_NODISCARD
441 ETL_CONSTEXPR14
442 to_arithmetic_status status() const
443 {
444 return conversion_status;
445 }
446
447 private:
448
449 etl::radix::value_type radix;
450 TValue maximum;
451 TValue integral_value;
452 to_arithmetic_status conversion_status;
453 };
454
455 //***************************************************************************
457 //***************************************************************************
458 struct floating_point_accumulator
459 {
460 //*********************************
461 ETL_CONSTEXPR14
462 floating_point_accumulator()
463 : divisor(1)
464 , floating_point_value(0)
465 , is_negative_mantissa(false)
466 , is_negative_exponent(false)
467 , expecting_sign(true)
468 , exponent_value(0)
469 , state(Parsing_Integral)
470 , conversion_status(to_arithmetic_status::Valid)
471 {
472 }
473
474 //*********************************
475 ETL_NODISCARD
476 ETL_CONSTEXPR14
477 bool add(char c)
478 {
479 bool is_success = true;
480
481 switch (state)
482 {
483 //***************************
484 case Parsing_Integral:
485 {
486 if (expecting_sign && ((c == char_constant::Positive_Char) || (c == char_constant::Negative_Char)))
487 {
488 is_negative_mantissa = (c == char_constant::Negative_Char);
489 expecting_sign = false;
490 }
491 // Radix point?
492 else if ((c == char_constant::Radix_Point1_Char) || (c == char_constant::Radix_Point2_Char))
493 {
494 expecting_sign = false;
495 state = Parsing_Fractional;
496 }
497 // Exponential?
498 else if (c == char_constant::Exponential_Char)
499 {
500 expecting_sign = true;
501 state = Parsing_Exponential;
502 }
503 else if (is_valid(c, etl::radix::decimal))
504 {
505 const char digit = digit_value(c, etl::radix::decimal);
506 floating_point_value *= 10;
507 is_negative_mantissa ? floating_point_value -= digit : floating_point_value += digit;
508 conversion_status = to_arithmetic_status::Valid;
509 expecting_sign = false;
510 }
511 else
512 {
513 conversion_status = to_arithmetic_status::Invalid_Format;
514 is_success = false;
515 }
516 break;
517 }
518
519 //***************************
520 case Parsing_Fractional:
521 {
522 // Radix point?
523 if ((c == char_constant::Radix_Point1_Char) || (c == char_constant::Radix_Point2_Char))
524 {
525 conversion_status = to_arithmetic_status::Invalid_Format;
526 is_success = false;
527 }
528 // Exponential?
529 else if (c == char_constant::Exponential_Char)
530 {
531 expecting_sign = true;
532 state = Parsing_Exponential;
533 }
534 else if (is_valid(c, etl::radix::decimal))
535 {
536 const char digit = digit_value(c, etl::radix::decimal);
537 divisor *= 10;
538 long double fraction = digit / divisor;
539 is_negative_mantissa ? floating_point_value -= fraction : floating_point_value += fraction;
540 conversion_status = to_arithmetic_status::Valid;
541 }
542 else
543 {
544 conversion_status = to_arithmetic_status::Invalid_Format;
545 is_success = false;
546 }
547 break;
548 }
549
550 //***************************
551 case Parsing_Exponential:
552 {
553 if (expecting_sign && ((c == char_constant::Positive_Char) || (c == char_constant::Negative_Char)))
554 {
555 is_negative_exponent = (c == char_constant::Negative_Char);
556 expecting_sign = false;
557 }
558 // Radix point?
559 else if ((c == char_constant::Radix_Point1_Char) || (c == char_constant::Radix_Point2_Char) || (c == char_constant::Exponential_Char))
560 {
561 conversion_status = to_arithmetic_status::Invalid_Format;
562 is_success = false;
563 }
564 else if (is_valid(c, etl::radix::decimal))
565 {
566 const char digit = digit_value(c, etl::radix::decimal);
567 exponent_value *= etl::radix::decimal;
568 is_negative_exponent ? exponent_value -= digit : exponent_value += digit;
569 }
570 else
571 {
572 conversion_status = to_arithmetic_status::Invalid_Format;
573 is_success = false;
574 }
575 break;
576 }
577
578 //***************************
579 default:
580 {
581 is_success = false;
582 break;
583 }
584 }
585
586 return is_success;
587 }
588
589 //*********************************
590 ETL_NODISCARD
591 ETL_CONSTEXPR14
592 bool has_value() const
593 {
594 return (conversion_status == to_arithmetic_status::Valid);
595 }
596
597 //*********************************
598 ETL_NODISCARD
599 ETL_CONSTEXPR14
600 long double value() const
601 {
602 return floating_point_value;
603 }
604
605 //*********************************
606 ETL_NODISCARD
607 ETL_CONSTEXPR14
608 to_arithmetic_status status() const
609 {
610 return conversion_status;
611 }
612
613 //*********************************
614 ETL_NODISCARD
615 ETL_CONSTEXPR14
616 int exponent() const
617 {
618 return exponent_value;
619 }
620
621 private:
622
623 enum
624 {
625 Parsing_Integral,
626 Parsing_Fractional,
627 Parsing_Exponential
628 };
629
630 long double divisor;
631 long double floating_point_value;
632 bool is_negative_mantissa;
633 bool is_negative_exponent;
634 bool expecting_sign;
635 int exponent_value;
636 int state;
637 to_arithmetic_status conversion_status;
638 };
639
640 //***************************************************************************
641 // Define an unsigned accumulator type that is at least as large as TValue.
642 //***************************************************************************
643 template <size_t Bits>
645
646 template <>
648 {
649 typedef uint32_t type;
650 };
651
652 template <>
654 {
655 typedef uint32_t type;
656 };
657
658 template <>
660 {
661 typedef uint32_t type;
662 };
663
664#if ETL_USING_64BIT_TYPES
665 template <>
667 {
668 typedef uint64_t type;
669 };
670#endif
671
672 //***************************************************************************
674 //***************************************************************************
675 template <typename TChar, typename TAccumulatorType>
676 ETL_NODISCARD
677 ETL_CONSTEXPR14
679 const etl::radix::value_type radix,
680 const TAccumulatorType maximum)
681 {
683 typedef typename etl::unexpected<etl::to_arithmetic_status> unexpected_type;
684
685 typename etl::basic_string_view<TChar>::const_iterator itr = view.begin();
686 const typename etl::basic_string_view<TChar>::const_iterator itr_end = view.end();
687
688 integral_accumulator<TAccumulatorType> accumulator(radix, maximum);
689
690 while ((itr != itr_end) && accumulator.add(convert(*itr)))
691 {
692 // Keep looping until done or an error occurs.
693 ++itr;
694 }
695
696 if (accumulator.has_value())
697 {
698 accumulator_result = accumulator.value();
699 }
700 else
701 {
702 accumulator_result = unexpected_type(accumulator.status());
703 }
704
705 return accumulator_result;
706 }
707 }
708
709 //***************************************************************************
711 //***************************************************************************
712 template <typename TValue, typename TChar>
713 ETL_NODISCARD
714 ETL_CONSTEXPR14
717 const etl::radix::value_type radix)
718 {
719 using namespace etl::private_to_arithmetic;
720
721 typedef etl::to_arithmetic_result<TValue> result_type;
722 typedef typename result_type::unexpected_type unexpected_type;
723
724 result_type result;
725
727 {
728 // Is this a negative number?
729 const bool is_negative = check_and_remove_sign_prefix(view);
730
731 if (view.empty())
732 {
733 result = unexpected_type(to_arithmetic_status::Invalid_Format);
734 }
735 else
736 {
737 // Make sure we're not trying to put a negative value into an unsigned type.
738 if (is_negative && etl::is_unsigned<TValue>::value)
739 {
740 result = unexpected_type(to_arithmetic_status::Signed_To_Unsigned);
741 }
742 else
743 {
744 const bool is_decimal = (radix == etl::radix::decimal);
745
746 // Select the type we use for the accumulator.
748
749 // Find the maximum absolute value for the type value we're trying to convert to.
750 const accumulator_type maximum = is_negative ? etl::absolute_unsigned(etl::integral_limits<TValue>::min)
753 // Do the conversion.
755
756 result = unexpected_type(accumulator_result.error());
757
758 // Was it successful?
759 if (accumulator_result.has_value())
760 {
761 typedef typename etl::make_unsigned<TValue>::type uvalue_t;
762 const uvalue_t uvalue = static_cast<uvalue_t>(accumulator_result.value());
763
764 // Convert from the accumulator type to the desired type.
765 result = (is_negative ? static_cast<TValue>(0) - uvalue : etl::bit_cast<TValue>(uvalue));
766 }
767 }
768 }
769 }
770 else
771 {
772 result = unexpected_type(to_arithmetic_status::Invalid_Radix);
773 }
774
775 return result;
776 }
777
778 //***************************************************************************
780 //***************************************************************************
781 template <typename TValue, typename TChar>
782 ETL_NODISCARD
783 ETL_CONSTEXPR14
786 {
787 return etl::to_arithmetic<TValue, TChar>(view, etl::radix::decimal);
788 }
789
790 //***************************************************************************
792 //***************************************************************************
793 template <typename TValue, typename TChar>
794 ETL_NODISCARD
795 ETL_CONSTEXPR14
798 {
799 return etl::to_arithmetic<TValue, TChar>(view, spec.base);
800 }
801
802 //***************************************************************************
804 //***************************************************************************
805 template <typename TValue, typename TChar>
806 ETL_NODISCARD
807 ETL_CONSTEXPR14
809 to_arithmetic(const TChar* cp, size_t length, const etl::radix::value_type radix)
810 {
812 }
813
814 //***************************************************************************
816 //***************************************************************************
817 template <typename TValue, typename TChar>
818 ETL_NODISCARD
819 ETL_CONSTEXPR14
821 to_arithmetic(const TChar* cp, size_t length)
822 {
823 return etl::to_arithmetic<TValue, TChar>(etl::basic_string_view<TChar>(cp, length), etl::radix::decimal);
824 }
825
826 //***************************************************************************
828 //***************************************************************************
829 template <typename TValue, typename TChar>
830 ETL_NODISCARD
831 ETL_CONSTEXPR14
833 to_arithmetic(const TChar* cp, size_t length, const typename etl::private_basic_format_spec::base_spec& spec)
834 {
836 }
837
838 //***************************************************************************
840 //***************************************************************************
841 template <typename TValue, typename TChar>
842 ETL_NODISCARD
843 ETL_CONSTEXPR14
845 to_arithmetic(const etl::ibasic_string<TChar>& str, const etl::radix::value_type radix)
846 {
848 }
849
850 //***************************************************************************
852 //***************************************************************************
853 template <typename TValue, typename TChar>
854 ETL_NODISCARD
855 ETL_CONSTEXPR14
861
862 //***************************************************************************
864 //***************************************************************************
865 template <typename TValue, typename TChar>
866 ETL_NODISCARD
867 ETL_CONSTEXPR14
873
874 //***************************************************************************
876 //***************************************************************************
877 template <typename TValue, typename TChar>
878 ETL_NODISCARD
879 ETL_CONSTEXPR14
882 {
883 using namespace etl::private_to_arithmetic;
884
885 typedef etl::to_arithmetic_result<TValue> result_type;
886 typedef typename result_type::unexpected_type unexpected_type;
887
888 result_type result;
889
890 if (view.empty())
891 {
892 result = unexpected_type(to_arithmetic_status::Invalid_Format);
893 }
894 else
895 {
896 floating_point_accumulator accumulator;
897
898 typename etl::basic_string_view<TChar>::const_iterator itr = view.begin();
899 const typename etl::basic_string_view<TChar>::const_iterator itr_end = view.end();
900
901 while ((itr != itr_end) && accumulator.add(convert(*itr)))
902 {
903 // Keep looping until done or an error occurs.
904 ++itr;
905 }
906
907 result = unexpected_type(accumulator.status());
908
909 if (result.has_value())
910 {
911 TValue value = static_cast<TValue>(accumulator.value());
912 int exponent = accumulator.exponent();
913
914 value *= pow(static_cast<TValue>(10.0), static_cast<TValue>(exponent));
915
916 // Check that the result is a valid floating point number.
917 if (etl::is_infinity(value))
918 {
919 result = unexpected_type(to_arithmetic_status::Overflow);
920 }
921 else if (etl::is_nan(value))
922 {
923 result = unexpected_type(to_arithmetic_status::Invalid_Float);
924 }
925 else
926 {
927 result = value;
928 }
929 }
930 }
931
932 return result;
933 }
934
935 //***************************************************************************
937 //***************************************************************************
938 template <typename TValue, typename TChar>
939 ETL_NODISCARD
940 ETL_CONSTEXPR14
942 to_arithmetic(const TChar* cp, size_t length)
943 {
945 }
946
947 //***************************************************************************
949 //***************************************************************************
950 template <typename TValue, typename TChar>
951 ETL_NODISCARD
952 ETL_CONSTEXPR14
958
959 //***************************************************************************
961 //***************************************************************************
962 template <typename TValue, typename TChar>
963 ETL_NODISCARD
964 ETL_CONSTEXPR14
970}
971
972//***************************************************************************
974//***************************************************************************
975template <typename T>
977{
978 if (lhs.has_value() && rhs.has_value())
979 {
980 return (lhs.value() == rhs.value());
981 }
982 else
983 {
984 return (lhs.status() == rhs.status());
985 }
986}
987
988//***************************************************************************
990//***************************************************************************
991template <typename T, typename U>
992ETL_CONSTEXPR14 bool operator ==(const etl::to_arithmetic_result<T>& lhs, const U& rhs)
993{
994 return bool(lhs) ? lhs.value() == rhs : false;
995}
996
997//***************************************************************************
999//***************************************************************************
1000template <typename T, typename U>
1001ETL_CONSTEXPR14 bool operator ==(const T& lhs, const etl::to_arithmetic_result<U>& rhs)
1002{
1003 return bool(rhs) ? rhs.value() == lhs : false;
1004}
1005
1006//***************************************************************************
1008//***************************************************************************
1009template <typename T>
1011{
1012 return !(lhs == rhs);
1013}
1014
1015//***************************************************************************
1017//***************************************************************************
1018template <typename T, typename U>
1019ETL_CONSTEXPR14 bool operator !=(const etl::to_arithmetic_result<T>& lhs, const U& rhs)
1020{
1021 return !(lhs == rhs);
1022}
1023
1024//***************************************************************************
1026//***************************************************************************
1027template <typename T, typename U>
1028ETL_CONSTEXPR14 bool operator !=(const T& lhs, const etl::to_arithmetic_result<T>& rhs)
1029{
1030 return !(lhs == rhs);
1031}
1032
1033#endif
String view.
Definition string_view.h:104
ETL_CONSTEXPR14 void remove_prefix(size_type n) ETL_NOEXCEPT
Shrinks the view by moving its start forward.
Definition string_view.h:395
ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
Returns a const iterator to the end of the array.
Definition string_view.h:220
ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition string_view.h:204
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the array size is zero.
Definition string_view.h:272
Definition basic_string.h:351
Status values for to_arithmetic.
Definition to_arithmetic.h:83
ETL_CONSTEXPR14 to_arithmetic_result(const to_arithmetic_result &other)
Copy constructor.
Definition to_arithmetic.h:104
ETL_CONSTEXPR14 to_arithmetic_result & operator=(value_type value_)
Assignment from a value.
Definition to_arithmetic.h:173
ETL_NODISCARD ETL_CONSTEXPR14 error_type error() const
Definition to_arithmetic.h:164
ETL_NODISCARD ETL_CONSTEXPR14 value_type value() const
Definition to_arithmetic.h:136
ETL_CONSTEXPR14 to_arithmetic_result()
Default constructor.
Definition to_arithmetic.h:94
ETL_NODISCARD ETL_CONSTEXPR14 bool has_value() const
Returns true if the result has a valid value.
Definition to_arithmetic.h:115
Definition expected.h:77
#define ETL_DECLARE_ENUM_TYPE(TypeName, ValueType)
Definition enum_type.h:85
Definition integral_limits.h:516
Definition radix.h:47
enable_if
Definition type_traits_generator.h:1254
is_unsigned
Definition type_traits_generator.h:1084
make_unsigned
Definition type_traits_generator.h:1244
bitset_ext
Definition absolute.h:39
ETL_NODISCARD ETL_CONSTEXPR14 etl::enable_if< etl::is_integral< TValue >::value, etl::to_arithmetic_result< TValue > >::type to_arithmetic(etl::basic_string_view< TChar > view, const etl::radix::value_type radix)
Text to integral from view and radix value type.
Definition to_arithmetic.h:716
ETL_NODISCARD etl::enable_if<!(etl::is_integral< TDestination >::value &&etl::is_integral< TSource >::value)&&(sizeof(TDestination)==sizeof(TSource))&&etl::is_trivially_copyable< TSource >::value &&etl::is_trivially_copyable< TDestination >::value, TDestination >::type bit_cast(const TSource &source) ETL_NOEXCEPT
bit_cast - Type to different type.
Definition bit.h:58
ETL_CONSTEXPR14 size_t strlen(const T *t) ETL_NOEXCEPT
Alternative strlen for all character types.
Definition char_traits.h:287
Definition basic_format_spec.h:48
Definition to_arithmetic.h:225
Definition to_arithmetic.h:201
Accumulate floating point.
Definition to_arithmetic.h:459
Accumulate integrals.
Definition to_arithmetic.h:366
Status values for to_arithmetic.
Definition to_arithmetic.h:57
ETL_CONSTEXPR14 bool operator==(const etl::to_arithmetic_result< T > &lhs, const etl::to_arithmetic_result< T > &rhs)
Equality test for etl::to_arithmetic_result.
Definition to_arithmetic.h:976
ETL_CONSTEXPR14 bool operator!=(const etl::to_arithmetic_result< T > &lhs, const etl::to_arithmetic_result< T > &rhs)
Inequality test for etl::to_arithmetic_result.
Definition to_arithmetic.h:1010
ETL_NODISCARD ETL_CONSTEXPR14 bool check_and_remove_sign_prefix(etl::basic_string_view< TChar > &view)
Definition to_arithmetic.h:327
ETL_NODISCARD ETL_CONSTEXPR14 etl::to_arithmetic_result< TAccumulatorType > to_arithmetic_integral(const etl::basic_string_view< TChar > &view, const etl::radix::value_type radix, const TAccumulatorType maximum)
Text to integral from view, radix value and maximum.
Definition to_arithmetic.h:678
ETL_NODISCARD ETL_CONSTEXPR14 bool is_valid_radix(const etl::radix::value_type radix)
Checks to see if the radix is valid.
Definition to_arithmetic.h:353