1 //=================================================================================================
2 /*!
3 // \file blaze/math/Accuracy.h
4 // \brief Computation accuracy for floating point data types
5 //
6 // Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved
7 //
8 // This file is part of the Blaze library. You can redistribute it and/or modify it under
9 // the terms of the New (Revised) BSD License. Redistribution and use in source and binary
10 // forms, with or without modification, are permitted provided that the following conditions
11 // are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice, this list of
14 // conditions and the following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
16 // of conditions and the following disclaimer in the documentation and/or other materials
17 // provided with the distribution.
18 // 3. Neither the names of the Blaze development group nor the names of its contributors
19 // may be used to endorse or promote products derived from this software without specific
20 // prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 */
33 //=================================================================================================
34
35 #ifndef _BLAZE_MATH_ACCURACY_H_
36 #define _BLAZE_MATH_ACCURACY_H_
37
38
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42
43 #include <blaze/util/constraints/FloatingPoint.h>
44 #include <blaze/util/Limits.h>
45
46
47 namespace blaze {
48
49 //=================================================================================================
50 //
51 // CLASS DEFINITION
52 //
53 //=================================================================================================
54
55 //*************************************************************************************************
56 /*!\brief Negative computation accuracy for floating point data types.
57 // \ingroup math
58 //
59 // The NegativeAccuracy class is a wrapper class around the functionality of the blaze::Limits
60 // class. It represents the negative computation accuracy of the Blaze library for any floating
61 // point data type. In order to assign a negative accuracy value, the NegativeAccuracy class can
62 // be implicitly converted to the three built-in floating point data types float, double and long
63 // double.
64 //
65 // \note The NegativeAccuracy class is a helper class for the Accuracy class. It cannot be
66 // instantiated on its own, but can only be used by the Accuracy class.
67 */
68 template< typename A > // Positive accuracy type
69 class NegativeAccuracy
70 {
71 public:
72 //**Type definitions****************************************************************************
73 using PositiveType = A; //!< The positive accuracy type.
74 //**********************************************************************************************
75
76 private:
77 //**Constructors********************************************************************************
78 /*!\name Constructors */
79 //@{
80 constexpr NegativeAccuracy();
81 NegativeAccuracy( const NegativeAccuracy& ) = default;
82 //@}
83 //**********************************************************************************************
84
85 public:
86 //**Destructor**********************************************************************************
87 /*!\name Destructor */
88 //@{
89 ~NegativeAccuracy() = default;
90 //@}
91 //**********************************************************************************************
92
93 //**Unary plus/minus operators******************************************************************
94 /*!\name Unary plus/minus operators */
95 //@{
96 constexpr const NegativeAccuracy& operator+() const;
97 constexpr const PositiveType operator-() const;
98 //@}
99 //**********************************************************************************************
100
101 //**Conversion operator*************************************************************************
102 /*!\name Conversion operator */
103 //@{
104 template< typename T >
105 constexpr operator const T() const;
106 //@}
107 //**********************************************************************************************
108
109 //**Forbidden operations************************************************************************
110 /*!\name Forbidden operations */
111 //@{
112 NegativeAccuracy& operator=( const NegativeAccuracy& ) = delete;
113 void* operator&() const = delete;
114 //@}
115 //**********************************************************************************************
116
117 private:
118 //**Friend declarations*************************************************************************
119 /*! \cond BLAZE_INTERNAL */
120 friend class Accuracy;
121 /*! \endcond */
122 //**********************************************************************************************
123 };
124 //*************************************************************************************************
125
126
127
128
129 //=================================================================================================
130 //
131 // CONSTRUCTORS
132 //
133 //=================================================================================================
134
135 //*************************************************************************************************
136 /*!\brief The default constructor of the NegativeAccuracy class.
137 */
138 template< typename A > // Positive accuracy type
NegativeAccuracy()139 constexpr NegativeAccuracy<A>::NegativeAccuracy()
140 {}
141 //*************************************************************************************************
142
143
144
145
146 //=================================================================================================
147 //
148 // UNARY PLUS/MINUS OPERATORS
149 //
150 //=================================================================================================
151
152 //*************************************************************************************************
153 /*!\brief Returns the negative computation accuracy for all floating point data types.
154 //
155 // \return The negative computation accuracy.
156 */
157 template< typename A > // Positive accuracy type
158 constexpr const NegativeAccuracy<A>& NegativeAccuracy<A>::operator+() const
159 {
160 return *this;
161 }
162 //*************************************************************************************************
163
164
165 //*************************************************************************************************
166 /*!\brief Returns the positive computation accuracy for all floating point data types.
167 //
168 // \return The positive computation accuracy.
169 */
170 template< typename A > // Positive accuracy type
171 constexpr const typename NegativeAccuracy<A>::PositiveType
172 NegativeAccuracy<A>::operator-() const
173 {
174 return PositiveType();
175 }
176 //*************************************************************************************************
177
178
179
180
181 //=================================================================================================
182 //
183 // CONVERSION OPERATOR
184 //
185 //=================================================================================================
186
187 //*************************************************************************************************
188 /*!\brief Conversion operator to the required floating point data type.
189 //
190 // The conversion operator returns the negative computation accuracy for the floating point
191 // data type \a T.
192 */
193 template< typename A > // Positive accuracy type
194 template< typename T > // Floating point data type
T()195 constexpr NegativeAccuracy<A>::operator const T() const
196 {
197 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
198 return -Limits<T>::accuracy();
199 }
200 //*************************************************************************************************
201
202
203
204
205 //=================================================================================================
206 //
207 // GLOBAL OPERATORS
208 //
209 //=================================================================================================
210
211 //*************************************************************************************************
212 /*!\name NegativeAccuracy operators */
213 //@{
214 template< typename A, typename T >
215 constexpr bool operator==( const NegativeAccuracy<A>& lhs, const T& rhs );
216
217 template< typename A, typename T >
218 constexpr bool operator==( const T& lhs, const NegativeAccuracy<A>& rhs );
219
220 template< typename A, typename T >
221 constexpr bool operator!=( const NegativeAccuracy<A>& lhs, const T& rhs );
222
223 template< typename A, typename T >
224 constexpr bool operator!=( const T& lhs, const NegativeAccuracy<A>& rhs );
225
226 template< typename A, typename T >
227 constexpr bool operator<( const NegativeAccuracy<A>& lhs, const T& rhs );
228
229 template< typename A, typename T >
230 constexpr bool operator<( const T& lhs, const NegativeAccuracy<A>& rhs );
231
232 template< typename A, typename T >
233 constexpr bool operator>( const NegativeAccuracy<A>& lhs, const T& rhs );
234
235 template< typename A, typename T >
236 constexpr bool operator>( const T& lhs, const NegativeAccuracy<A>& rhs );
237 //@}
238 //*************************************************************************************************
239
240
241 //*************************************************************************************************
242 /*!\brief Equality comparison between a NegativeAccuracy object and a floating point value.
243 // \ingroup math
244 //
245 // \param rhs The right-hand side floating point value.
246 // \return \a true if the value is equal to the negative accuracy, \a false if not.
247 //
248 // This operator exclusively works for floating point data types. The attempt to compare any
249 // integral data type or user-defined class types will result in a compile time error.
250 */
251 template< typename A // Positive accuracy type
252 , typename T > // Floating point data type
253 constexpr bool operator==( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
254 {
255 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
256 return -Limits<T>::accuracy() == rhs;
257 }
258 //*************************************************************************************************
259
260
261 //*************************************************************************************************
262 /*!\brief Equality comparison between a floating point value and a NegativeAccuracy object.
263 // \ingroup math
264 //
265 // \param lhs The left-hand side floating point value.
266 // \return \a true if the value is equal to the negative accuracy, \a false if not.
267 //
268 // This operator exclusively works for floating point data types. The attempt to compare any
269 // integral data type or user-defined class types will result in a compile time error.
270 */
271 template< typename A // Positive accuracy type
272 , typename T > // Floating point data type
273 constexpr bool operator==( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
274 {
275 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
276 return lhs == -Limits<T>::accuracy();
277 }
278 //*************************************************************************************************
279
280
281 //*************************************************************************************************
282 /*!\brief Inequality comparison between a NegativeAccuracy object and a floating point value.
283 // \ingroup math
284 //
285 // \param rhs The right-hand side floating point value.
286 // \return \a true if the value is unequal to the negative accuracy, \a false if not.
287 //
288 // This operator exclusively works for floating point data types. The attempt to compare any
289 // integral data type or user-defined class types will result in a compile time error.
290 */
291 template< typename A // Positive accuracy type
292 , typename T > // Floating point data type
293 constexpr bool operator!=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
294 {
295 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
296 return -Limits<T>::accuracy() != rhs;
297 }
298 //*************************************************************************************************
299
300
301 //*************************************************************************************************
302 /*!\brief Inequality comparison between a floating point value and a NegativeAccuracy object.
303 // \ingroup math
304 //
305 // \param lhs The left-hand side floating point value.
306 // \return \a true if the value is unequal to the negative accuracy, \a false if not.
307 //
308 // This operator exclusively works for floating point data types. The attempt to compare any
309 // integral data type or user-defined class types will result in a compile time error.
310 */
311 template< typename A // Positive accuracy type
312 , typename T > // Floating point data type
313 constexpr bool operator!=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
314 {
315 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
316 return lhs != -Limits<T>::accuracy();
317 }
318 //*************************************************************************************************
319
320
321 //*************************************************************************************************
322 /*!\brief Less-than comparison between a NegativeAccuracy object and a floating point value.
323 //
324 // \param rhs The right-hand side floating point value.
325 // \return \a true if the value is greater than the negative accuracy, \a false if not.
326 //
327 // This operator exclusively works for floating point data types. The attempt to compare any
328 // integral data type or user-defined class types will result in a compile time error.
329 */
330 template< typename A // Positive accuracy type
331 , typename T > // Floating point data type
332 constexpr bool operator<( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
333 {
334 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
335 return -Limits<T>::accuracy() < rhs;
336 }
337 //*************************************************************************************************
338
339
340 //*************************************************************************************************
341 /*!\brief Less-than comparison between a floating point value and a NegativeAccuracy object.
342 //
343 // \param lhs The left-hand side floating point value.
344 // \return \a true if the value is smaller than the negative accuracy, \a false if not.
345 //
346 // This operator exclusively works for floating point data types. The attempt to compare any
347 // integral data type or user-defined class types will result in a compile time error.
348 */
349 template< typename A // Positive accuracy type
350 , typename T > // Floating point data type
351 constexpr bool operator<( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
352 {
353 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
354 return lhs < -Limits<T>::accuracy();
355 }
356 //*************************************************************************************************
357
358
359 //*************************************************************************************************
360 /*!\brief Greater-than comparison between a NegativeAccuracy object and a floating point value.
361 //
362 // \param rhs The right-hand side floating point value.
363 // \return \a true if the value is smaller than the negative accuracy, \a false if not.
364 //
365 // This operator exclusively works for floating point data types. The attempt to compare any
366 // integral data type or user-defined class types will result in a compile time error.
367 */
368 template< typename A // Positive accuracy type
369 , typename T > // Floating point data type
370 constexpr bool operator>( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
371 {
372 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
373 return -Limits<T>::accuracy() > rhs;
374 }
375 //*************************************************************************************************
376
377
378 //*************************************************************************************************
379 /*!\brief Greater-than comparison between a floating point value and a NegativeAccuracy object.
380 //
381 // \param lhs The left-hand side floating point value.
382 // \return \a true if the value is greater than the negative accuracy, \a false if not.
383 //
384 // This operator exclusively works for floating point data types. The attempt to compare any
385 // integral data type or user-defined class types will result in a compile time error.
386 */
387 template< typename A // Positive accuracy type
388 , typename T > // Floating point data type
389 constexpr bool operator>( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
390 {
391 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
392 return lhs > -Limits<T>::accuracy();
393 }
394 //*************************************************************************************************
395
396
397 //*************************************************************************************************
398 /*!\brief Less-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
399 //
400 // \param rhs The right-hand side floating point value.
401 // \return \a true if the value is greater than or equal to the negative accuracy, \a false if not.
402 //
403 // This operator exclusively works for floating point data types. The attempt to compare any
404 // integral data type or user-defined class types will result in a compile time error.
405 */
406 template< typename A // Positive accuracy type
407 , typename T > // Floating point data type
408 constexpr bool operator<=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
409 {
410 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
411 return -Limits<T>::accuracy() <= rhs;
412 }
413 //*************************************************************************************************
414
415
416 //*************************************************************************************************
417 /*!\brief Less-or-equal-than comparison between a floating point value and a NegativeAccuracy object.
418 //
419 // \param lhs The left-hand side floating point value.
420 // \return \a true if the value is smaller than or equal to the negative accuracy, \a false if not.
421 //
422 // This operator exclusively works for floating point data types. The attempt to compare any
423 // integral data type or user-defined class types will result in a compile time error.
424 */
425 template< typename A // Positive accuracy type
426 , typename T > // Floating point data type
427 constexpr bool operator<=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
428 {
429 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
430 return lhs <= -Limits<T>::accuracy();
431 }
432 //*************************************************************************************************
433
434
435 //*************************************************************************************************
436 /*!\brief Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
437 //
438 // \param rhs The right-hand side floating point value.
439 // \return \a true if the value is smaller than or equal to the negative accuracy, \a false if not.
440 //
441 // This operator exclusively works for floating point data types. The attempt to compare any
442 // integral data type or user-defined class types will result in a compile time error.
443 */
444 template< typename A // Positive accuracy type
445 , typename T > // Floating point data type
446 constexpr bool operator>=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
447 {
448 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
449 return -Limits<T>::accuracy() >= rhs;
450 }
451 //*************************************************************************************************
452
453
454 //*************************************************************************************************
455 /*!\brief Less-or-equal-than comparison between a floating point value and a NegativeAccuracy object.
456 //
457 // \param lhs The left-hand side floating point value.
458 // \return \a true if the value is greater than or equal to the negative accuracy, \a false if not.
459 //
460 // This operator exclusively works for floating point data types. The attempt to compare any
461 // integral data type or user-defined class types will result in a compile time error.
462 */
463 template< typename A // Positive accuracy type
464 , typename T > // Floating point data type
465 constexpr bool operator>=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
466 {
467 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
468 return lhs >= -Limits<T>::accuracy();
469 }
470 //*************************************************************************************************
471
472
473
474
475
476
477
478
479 //=================================================================================================
480 //
481 // CLASS DEFINITION
482 //
483 //=================================================================================================
484
485 //*************************************************************************************************
486 /*!\brief Computation accuracy for floating point data types.
487 // \ingroup math
488 //
489 // The Accuracy class is a wrapper class around the functionality of the blaze::Limits class.
490 // It represents the computation accuracy of the Blaze library for any floating point data
491 // type. In order to assign an accuracy value, the Accuracy class can be implicitly converted
492 // to the three built-in floating point data types float, double and long double.\n
493 // In order to handle accuracy values conveniently, the global Accuracy instance blaze::accuracy
494 // is provided, which can be used wherever a floating point data value is required.
495
496 \code
497 float f = accuracy; // Assigns the positive computation accuracy for single precision values
498 double d = -accuracy; // Assigns the negative computation accuracy for double precision values
499 \endcode
500 */
501 class Accuracy
502 {
503 public:
504 //**Type definitions****************************************************************************
505 using NegativeType = NegativeAccuracy<Accuracy>; //!< The negated accuracy type.
506 //**********************************************************************************************
507
508 //**Constructors********************************************************************************
509 /*!\name Constructors */
510 //@{
511 constexpr Accuracy();
512 Accuracy( const Accuracy& ) = default;
513 //@}
514 //**********************************************************************************************
515
516 //**Destructor**********************************************************************************
517 /*!\name Destructor */
518 //@{
519 ~Accuracy() = default;
520 //@}
521 //**********************************************************************************************
522
523 //**Unary plus/minus operators******************************************************************
524 /*!\name Unary plus/minus operators */
525 //@{
526 constexpr const Accuracy& operator+() const;
527 constexpr const NegativeType operator-() const;
528 //@}
529 //**********************************************************************************************
530
531 //**Conversion operator*************************************************************************
532 /*!\name Conversion operator */
533 //@{
534 template< typename T >
535 constexpr operator const T() const;
536 //@}
537 //**********************************************************************************************
538
539 //**Forbidden operations************************************************************************
540 /*!\name Forbidden operations */
541 //@{
542 Accuracy& operator=( const Accuracy& ) = delete;
543 void* operator&() const = delete;
544 //@}
545 //**********************************************************************************************
546 };
547 //*************************************************************************************************
548
549
550
551
552 //=================================================================================================
553 //
554 // CONSTRUCTORS
555 //
556 //=================================================================================================
557
558 //*************************************************************************************************
559 /*!\brief The default constructor of the Accuracy class.
560 */
Accuracy()561 constexpr Accuracy::Accuracy()
562 {}
563 //*************************************************************************************************
564
565
566
567
568 //=================================================================================================
569 //
570 // UNARY PLUS/MINUS OPERATORS
571 //
572 //=================================================================================================
573
574 //*************************************************************************************************
575 /*!\brief Returns the positive computation accuracy for all floating point data types.
576 //
577 // \return The positive computation accuracy.
578 */
579 constexpr const Accuracy& Accuracy::operator+() const
580 {
581 return *this;
582 }
583 //*************************************************************************************************
584
585
586 //*************************************************************************************************
587 /*!\brief Returns the negative computation accuracy for all floating point data types.
588 //
589 // \return The negative computation accuracy.
590 */
591 constexpr const Accuracy::NegativeType Accuracy::operator-() const
592 {
593 return NegativeType();
594 }
595 //*************************************************************************************************
596
597
598
599
600 //=================================================================================================
601 //
602 // CONVERSION OPERATOR
603 //
604 //=================================================================================================
605
606 //*************************************************************************************************
607 /*!\brief Conversion operator to the required floating point data type.
608 //
609 // The conversion operator returns the computation accuracy for the floating point data
610 // type \a T.
611 */
612 template< typename T > // Floating point data type
T()613 constexpr Accuracy::operator const T() const
614 {
615 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
616 return Limits<T>::accuracy();
617 }
618 //*************************************************************************************************
619
620
621
622
623 //=================================================================================================
624 //
625 // GLOBAL OPERATORS
626 //
627 //=================================================================================================
628
629 //*************************************************************************************************
630 /*!\name Accuracy operators */
631 //@{
632 template< typename T >
633 constexpr bool operator==( const Accuracy& lhs, const T& rhs );
634
635 template< typename T >
636 constexpr bool operator==( const T& lhs, const Accuracy& rhs );
637
638 template< typename T >
639 constexpr bool operator!=( const Accuracy& lhs, const T& rhs );
640
641 template< typename T >
642 constexpr bool operator!=( const T& lhs, const Accuracy& rhs );
643
644 template< typename T >
645 constexpr bool operator<( const Accuracy& lhs, const T& rhs );
646
647 template< typename T >
648 constexpr bool operator<( const T& lhs, const Accuracy& rhs );
649
650 template< typename T >
651 constexpr bool operator>( const Accuracy& lhs, const T& rhs );
652
653 template< typename T >
654 constexpr bool operator>( const T& lhs, const Accuracy& rhs );
655
656 template< typename T >
657 constexpr bool operator<=( const Accuracy& lhs, const T& rhs );
658
659 template< typename T >
660 constexpr bool operator<=( const T& lhs, const Accuracy& rhs );
661
662 template< typename T >
663 constexpr bool operator>=( const Accuracy& lhs, const T& rhs );
664
665 template< typename T >
666 constexpr bool operator>=( const T& lhs, const Accuracy& rhs );
667 //@}
668 //*************************************************************************************************
669
670
671 //*************************************************************************************************
672 /*!\brief Equality comparison between an Accuracy object and a floating point value.
673 // \ingroup math
674 //
675 // \param rhs The right-hand side floating point value.
676 // \return \a true if the floating point value is equal to the accuracy, \a false if not.
677 //
678 // This operator exclusively works for floating point data types. The attempt to compare any
679 // integral data type or user-defined class types will result in a compile time error.
680 */
681 template< typename T > // Floating point data type
682 constexpr bool operator==( const Accuracy& /*lhs*/, const T& rhs )
683 {
684 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
685 return Limits<T>::accuracy() == rhs;
686 }
687 //*************************************************************************************************
688
689
690 //*************************************************************************************************
691 /*!\brief Equality comparison between a floating point value and an Accuracy object.
692 // \ingroup math
693 //
694 // \param lhs The left-hand side floating point value.
695 // \return \a true if the floating point value is equal to the accuracy, \a false if not.
696 //
697 // This operator exclusively works for floating point data types. The attempt to compare any
698 // integral data type or user-defined class types will result in a compile time error.
699 */
700 template< typename T > // Floating point data type
701 constexpr bool operator==( const T& lhs, const Accuracy& /*rhs*/ )
702 {
703 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
704 return lhs == Limits<T>::accuracy();
705 }
706 //*************************************************************************************************
707
708
709 //*************************************************************************************************
710 /*!\brief Inequality comparison between an Accuracy object and a floating point value.
711 // \ingroup math
712 //
713 // \param rhs The right-hand side floating point value.
714 // \return \a true if the floating point value is unequal to the accuracy, \a false if not.
715 //
716 // This operator exclusively works for floating point data types. The attempt to compare any
717 // integral data type or user-defined class types will result in a compile time error.
718 */
719 template< typename T > // Floating point data type
720 constexpr bool operator!=( const Accuracy& /*lhs*/, const T& rhs )
721 {
722 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
723 return Limits<T>::accuracy() != rhs;
724 }
725 //*************************************************************************************************
726
727
728 //*************************************************************************************************
729 /*!\brief Inequality comparison between a floating point value and an Accuracy object.
730 // \ingroup math
731 //
732 // \param lhs The left-hand side floating point value.
733 // \return \a true if the floating point value is unequal to the accuracy, \a false if not.
734 //
735 // This operator exclusively works for floating point data types. The attempt to compare any
736 // integral data type or user-defined class types will result in a compile time error.
737 */
738 template< typename T > // Floating point data type
739 constexpr bool operator!=( const T& lhs, const Accuracy& /*rhs*/ )
740 {
741 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
742 return lhs != Limits<T>::accuracy();
743 }
744 //*************************************************************************************************
745
746
747 //*************************************************************************************************
748 /*!\brief Less-than comparison between an Accuracy object and a floating point value.
749 //
750 // \param rhs The right-hand side floating point value.
751 // \return \a true if the floatin point value is greater than the accuracy, \a false if not.
752 //
753 // This operator exclusively works for floating point data types. The attempt to compare any
754 // integral data type or user-defined class types will result in a compile time error.
755 */
756 template< typename T > // Floating point data type
757 constexpr bool operator<( const Accuracy& /*lhs*/, const T& rhs )
758 {
759 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
760 return Limits<T>::accuracy() < rhs;
761 }
762 //*************************************************************************************************
763
764
765 //*************************************************************************************************
766 /*!\brief Less-than comparison between a floating point value and an Accuracy object.
767 //
768 // \param lhs The left-hand side floating point value.
769 // \return \a true if the floating point value is smaller than the accuracy, \a false if not.
770 //
771 // This operator exclusively works for floating point data types. The attempt to compare any
772 // integral data type or user-defined class types will result in a compile time error.
773 */
774 template< typename T > // Floating point data type
775 constexpr bool operator<( const T& lhs, const Accuracy& /*rhs*/ )
776 {
777 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
778 return lhs < Limits<T>::accuracy();
779 }
780 //*************************************************************************************************
781
782
783 //*************************************************************************************************
784 /*!\brief Greater-than comparison between an Accuracy object and a floating point value.
785 //
786 // \param rhs The right-hand side floating point value.
787 // \return \a true if the floating point value is smaller than the accuracy, \a false if not.
788 //
789 // This operator exclusively works for floating point data types. The attempt to compare any
790 // integral data type or user-defined class types will result in a compile time error.
791 */
792 template< typename T > // Floating point data type
793 constexpr bool operator>( const Accuracy& /*lhs*/, const T& rhs )
794 {
795 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
796 return Limits<T>::accuracy() > rhs;
797 }
798 //*************************************************************************************************
799
800
801 //*************************************************************************************************
802 /*!\brief Greater-than comparison between a floating point value and an Accuracy object.
803 //
804 // \param lhs The left-hand side floating point value.
805 // \return \a true if the floating point value is greater than the accuracy, \a false if not.
806 //
807 // This operator exclusively works for floating point data types. The attempt to compare any
808 // integral data type or user-defined class types will result in a compile time error.
809 */
810 template< typename T > // Floating point data type
811 constexpr bool operator>( const T& lhs, const Accuracy& /*rhs*/ )
812 {
813 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
814 return lhs > Limits<T>::accuracy();
815 }
816 //*************************************************************************************************
817
818
819 //*************************************************************************************************
820 /*!\brief Less-or-equal-than comparison between an Accuracy object and a floating point value.
821 //
822 // \param rhs The right-hand side floating point value.
823 // \return \a true if the floating point value is greater than or equal to the accuracy, \a false if not.
824 //
825 // This operator exclusively works for floating point data types. The attempt to compare any
826 // integral data type or user-defined class types will result in a compile time error.
827 */
828 template< typename T > // Floating point data type
829 constexpr bool operator<=( const Accuracy& /*lhs*/, const T& rhs )
830 {
831 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
832 return Limits<T>::accuracy() <= rhs;
833 }
834 //*************************************************************************************************
835
836
837 //*************************************************************************************************
838 /*!\brief Less-or-equal-than comparison between a floating point value and an Accuracy object.
839 //
840 // \param lhs The left-hand side floating point value.
841 // \return \a true if the value is smaller than or equal to the accuracy, \a false if not.
842 //
843 // This operator exclusively works for floating point data types. The attempt to compare any
844 // integral data type or user-defined class types will result in a compile time error.
845 */
846 template< typename T > // Floating point data type
847 constexpr bool operator<=( const T& lhs, const Accuracy& /*rhs*/ )
848 {
849 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
850 return lhs <= Limits<T>::accuracy();
851 }
852 //*************************************************************************************************
853
854
855 //*************************************************************************************************
856 /*!\brief Greater-or-equal-than comparison between an Accuracy object and a floating point value.
857 //
858 // \param rhs The right-hand side floating point value.
859 // \return \a true if the value is smaller than or equal to the accuracy, \a false if not.
860 //
861 // This operator exclusively works for floating point data types. The attempt to compare any
862 // integral data type or user-defined class types will result in a compile time error.
863 */
864 template< typename T > // Floating point data type
865 constexpr bool operator>=( const Accuracy& /*lhs*/, const T& rhs )
866 {
867 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
868 return Limits<T>::accuracy() >= rhs;
869 }
870 //*************************************************************************************************
871
872
873 //*************************************************************************************************
874 /*!\brief Less-or-equal-than comparison between a floating point value and an Accuracy object.
875 //
876 // \param lhs The left-hand side floating point value.
877 // \return \a true if the value is greater than or equal to the accuracy, \a false if not.
878 //
879 // This operator exclusively works for floating point data types. The attempt to compare any
880 // integral data type or user-defined class types will result in a compile time error.
881 */
882 template< typename T > // Floating point data type
883 constexpr bool operator>=( const T& lhs, const Accuracy& /*rhs*/ )
884 {
885 BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
886 return lhs >= Limits<T>::accuracy();
887 }
888 //*************************************************************************************************
889
890
891
892
893 //=================================================================================================
894 //
895 // GLOBAL ACCURACY VALUE
896 //
897 //=================================================================================================
898
899 //*************************************************************************************************
900 /*!\brief Global Accuracy instance.
901 // \ingroup math
902 //
903 // The blaze::accuracy instance can be used wherever a floating point data type is expected.
904 // It is implicitly converted to the corresponding floating point data type and represents
905 // the computation accuracy of the Blaze library for the according data type.
906 */
907 constexpr Accuracy accuracy;
908 //*************************************************************************************************
909
910 } // namespace blaze
911
912 #endif
913