half  1.12
IEEE 754-based half-precision floating point library
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
half.hpp
Go to the documentation of this file.
1 // half - IEEE 754-based half-precision floating point library.
2 //
3 // Copyright (c) 2012-2017 Christian Rau <rauy@users.sourceforge.net>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
6 // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
7 // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 
17 // This is a dummy header file to provide a clean interface documentation to Doxygen, without any ugly internals.
18 
21 
22 
41 #define HALF_ROUND_STYLE -1
42 
48 #define HALF_ROUND_TIES_TO_EVEN 0
49 
55 #define HUGE_VALH std::numeric_limits<half_float::half>::infinity()
56 
63 #define FP_FAST_FMAH 1
64 
65 
68 namespace half_float
69 {
90  struct half
91  {
94 
98  constexpr half() noexcept;
99 
102  explicit half(float rhs);
103 
106  operator float() const;
107 
111  half& operator=(float rhs);
112 
116 
122  half& operator+=(half rhs);
123 
129  half& operator-=(half rhs);
130 
136  half& operator*=(half rhs);
137 
143  half& operator/=(half rhs);
144 
149  half& operator+=(float rhs);
150 
155  half& operator-=(float rhs);
156 
161  half& operator*=(float rhs);
162 
167  half& operator/=(float rhs);
168 
172 
176  half& operator++();
177 
181  half& operator--();
182 
186  half operator++(int);
187 
191  half operator--(int);
193  };
194 
195 
198 
204  bool operator==(half a, half b);
205 
211  bool operator!=(half a, half b);
212 
218  bool operator<(half a, half b);
219 
225  bool operator>(half a, half b);
226 
232  bool operator<=(half a, half b);
233 
239  bool operator>=(half a, half b);
240 
244 
250  half operator+(half a, half b);
251 
257  half operator-(half a, half b);
258 
264  half operator*(half a, half b);
265 
271  half operator/(half a, half b);
272 
276  half constexpr operator+(half h);
277 
281  half constexpr operator-(half h);
282 
286 
293  template<typename charT,typename traits> std::basic_ostream<charT,traits>& operator<<(std::basic_ostream<charT,traits> &out, half h);
294 
301  template<typename charT,typename traits> std::basic_istream<charT,traits>& operator>>(std::basic_istream<charT,traits> &in, half &h);
302 
306 
310  half abs(half arg);
311 
315  half fabs(half arg);
316 
322  half fmod(half x, half y);
323 
329  half remainder(half x, half y);
330 
337  half remquo(half x, half y, int *quo);
338 
346  half fma(half x, half y, half z);
347 
352  half fmin(half x, half y);
353 
358  half fmax(half x, half y);
359 
365  half fdim(half x, half y);
366 
369  half nanh(const char*);
370 
374 
379  half exp(half arg);
380 
385  half exp2(half arg);
386 
391  half expm1(half arg);
392 
397  half log(half arg);
398 
403  half log10(half arg);
404 
409  half log1p(half arg);
410 
415  half log2(half arg);
416 
420 
425  half sqrt(half arg);
426 
431  half cbrt(half arg);
432 
438  half hypot(half x, half y);
439 
445  half pow(half base, half exp);
446 
450 
455  half sin(half arg);
456 
461  half cos(half arg);
462 
467  half tan(half arg);
468 
473  half asin(half arg);
474 
479  half acos(half arg);
480 
485  half atan(half arg);
486 
492  half atan2(half x, half y);
493 
497 
502  half sinh(half arg);
503 
508  half cosh(half arg);
509 
514  half tanh(half arg);
515 
520  half asinh(half arg);
521 
526  half acosh(half arg);
527 
532  half atanh(half arg);
533 
537 
542  half erf(half arg);
543 
548  half erfc(half arg);
549 
554  half lgamma(half arg);
555 
560  half tgamma(half arg);
561 
565 
569  half ceil(half arg);
570 
574  half floor(half arg);
575 
579  half trunc(half arg);
580 
584  half round(half arg);
585 
589  long lround(half arg);
590 
595  long long llround(half arg);
596 
601  half nearbyint(half arg);
602 
607  half rint(half arg);
608 
613  long lrint(half arg);
614 
620  long long llrint(half arg);
621 
625 
630  half frexp(half arg, int *exp);
631 
636  half ldexp(half arg, int exp);
637 
642  half modf(half x, half *iptr);
643 
648  half scalbn(half x, int exp);
649 
654  half scalbln(half x, long exp);
655 
662  int ilogb(half arg);
663 
667  half logb(half arg);
668 
673  half nextafter(half from, half to);
674 
679  half nexttoward(half from, long double to);
680 
685  half copysign(half x, half y);
686 
690 
698  int fpclassify(half arg);
699 
704  bool isfinite(half arg);
705 
710  bool isinf(half arg);
711 
716  bool isnan(half arg);
717 
722  bool isnormal(half arg);
723 
728  bool signbit(half arg);
729 
733 
739  bool isgreater(half x, half y);
740 
746  bool isgreaterequal(half x, half y);
747 
753  bool isless(half x, half y);
754 
760  bool islessequal(half x, half y);
761 
767  bool islessgreater(half x, half y);
768 
774  bool isunordered(half x, half y);
775 
779 
792  template<typename T,typename U> T half_cast(const U &arg);
793 
806  template<typename T,std::float_round_style R,typename U> T half_cast(const U &arg);
808 
809 
817  namespace literal
818  {
824  half operator""_h(long double value);
825  }
826 }
827 
828 
830 namespace std
831 {
837  template<> struct numeric_limits<half_float::half> : public std::numeric_limits<float>
838  {
840  static constexpr bool is_signed = true;
841 
843  static constexpr bool is_exact = false;
844 
846  static constexpr bool is_modulo = false;
847 
849  static constexpr bool is_iec559 = true;
850 
852  static constexpr bool has_infinity = true;
853 
855  static constexpr bool has_quiet_NaN = true;
856 
858  static constexpr std::float_denorm_style has_denorm = std::denorm_present;
859 
865  static constexpr std::float_round_style round_style = /* unspecified */;
866 
868  static constexpr int digits = 11;
869 
871  static constexpr int digits10 = 3;
872 
874  static constexpr int max_digits10 = 5;
875 
877  static constexpr int radix = 2;
878 
880  static constexpr int min_exponent = -13;
881 
883  static constexpr int min_exponent10 = -4;
884 
886  static constexpr int max_exponent = 16;
887 
889  static constexpr int max_exponent10 = 4;
890 
892  static constexpr half_float::half min() noexcept;
893 
895  static constexpr half_float::half lowest() noexcept;
896 
898  static constexpr half_float::half max() noexcept;
899 
901  static constexpr half_float::half epsilon() noexcept;
902 
904  static constexpr half_float::half round_error() noexcept;
905 
907  static constexpr half_float::half infinity() noexcept;
908 
910  static constexpr half_float::half quiet_NaN() noexcept;
911 
913  static constexpr half_float::half signaling_NaN() noexcept;
914 
916  static constexpr half_float::half denorm_min() noexcept;
917  };
918 
923  template<> struct hash<half_float::half>
924  {
927 
929  typedef std::size_t result_type;
930 
934  std::size_t operator()(half_float::half arg) const;
935  };
936 }