GteFunctions.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
12 #include <limits>
13 
14 namespace gte
15 {
16 
17 template <typename Real>
18 class Function
19 {
20 public:
21  static Real ACos(Real const& x); // acos(x)
22  static Real ACosh(Real const& x); // acosh(x)
23  static Real ASin(Real const& x); // asin(x)
24  static Real ASinh(Real const& x); // asinh(x)
25  static Real ATan(Real const& x); // atan(x)
26  static Real ATanh(Real const& x); // atanh(x)
27  static Real ATan2(Real const& y, Real const& x); // atan2(y, x)
28  static Real ATanpi(Real const& x); // atan(x)/pi
29  static Real ATan2pi(Real const& y, Real const& x); // atan2(y,x)/pi
30  static Real Ceil(Real const& x); // ceil(x)
31  static Real Cos(Real const& x); // cos(x)
32  static Real Cosh(Real const& x); // cosh(x)
33  static Real Cospi(Real const& x); // cos(pi*x)
34  static Real Exp(Real const& x); // e^x
35  static Real Exp2(Real const& x); // 2^x
36  static Real Exp10(Real const& x); // 10^x
37  static Real FAbs(Real const& x); // |x|
38  static Real Floor(Real const& x); // floor(x)
39  static Real FMod(Real const& x, Real const& y); // fmod(x,y)
40  static Real InvSqrt(Real const& x); // x^{-1/2}
41  static Real Log(Real const& x); // log_e(x)
42  static Real Log2(Real const& x); // log_2(x)
43  static Real Log10(Real const& x); // log_10(x)
44  static Real Pow(Real const& x, Real const& y); // x^y
45  static Real Sin(Real const& x); // sin(x)
46  static Real Sinh(Real const& x); // sinh(x)
47  static Real Sinpi(Real const& x); // sin(pi*x)
48  static Real Sqr(Real const& x); // x^2
49  static Real Sqrt(Real const& x); // x^{1/2}
50  static Real Tan(Real const& x); // tan(x)
51  static Real Tanh(Real const& x); // tanh(x)
52 
53  static Real Sign(Real const& x); // sign of x as a Real number
54  static int ISign(Real const& x); // sign of x as an integer
55 
56  // Clamp x to the interval [min,max].
57  static Real Clamp(Real const& x, Real const& min, Real const & max);
58 
59  // Clamp x to the interval [0,1].
60  static Real Saturate(Real const& x);
61 
62  // The maximum number of bisections required for root finding on an
63  // interval of finite floating-point numbers. After this number of
64  // iterations, the root-bounding interval consists of two consecutive
65  // floating-point numbers. Thus, you have reached the limit of the
66  // precision of the numbers. WARNING: The return value for BSNumber
67  // or BSRational types is std::numeric_limits<unsigned int>::max(),
68  // because there is no limit on precision (other than the practical
69  // limitations of memory usage and computational costs). We recommend
70  // you use a reasonable number of the BS* types.
71  static unsigned int GetMaxBisections();
72 
73 private:
74  // The tag-dispatch pattern is used for template-parameter-controlled
75  // instantiation of mathematics functions.
76 
77  template <typename T> static T ACosImpl(T x, Arithmetic::IsFPType tag);
78  template <typename T> static T ACosImpl(T x, Arithmetic::IsFP16Type tag);
79  template <typename T> static T ACosImpl(T const& x, Arithmetic::IsBSType tag);
80 
81  template <typename T> static T ACoshImpl(T x, Arithmetic::IsFPType tag);
82  template <typename T> static T ACoshImpl(T x, Arithmetic::IsFP16Type tag);
83  template <typename T> static T ACoshImpl(T const& x, Arithmetic::IsBSType tag);
84 
85  template <typename T> static T ASinImpl(T x, Arithmetic::IsFPType tag);
86  template <typename T> static T ASinImpl(T x, Arithmetic::IsFP16Type tag);
87  template <typename T> static T ASinImpl(T const& x, Arithmetic::IsBSType tag);
88 
89  template <typename T> static T ASinhImpl(T x, Arithmetic::IsFPType tag);
90  template <typename T> static T ASinhImpl(T x, Arithmetic::IsFP16Type tag);
91  template <typename T> static T ASinhImpl(T const& x, Arithmetic::IsBSType tag);
92 
93  template <typename T> static T ATanImpl(T x, Arithmetic::IsFPType tag);
94  template <typename T> static T ATanImpl(T x, Arithmetic::IsFP16Type tag);
95  template <typename T> static T ATanImpl(T const& x, Arithmetic::IsBSType tag);
96 
97  template <typename T> static T ATanhImpl(T x, Arithmetic::IsFPType tag);
98  template <typename T> static T ATanhImpl(T x, Arithmetic::IsFP16Type tag);
99  template <typename T> static T ATanhImpl(T const& x, Arithmetic::IsBSType tag);
100 
101  template <typename T> static T ATan2Impl(T y, T x, Arithmetic::IsFPType tag);
102  template <typename T> static T ATan2Impl(T y, T x, Arithmetic::IsFP16Type tag);
103  template <typename T> static T ATan2Impl(T const& y, T const& x, Arithmetic::IsBSType tag);
104 
105  template <typename T> static T ATanpiImpl(T x, Arithmetic::IsFPType tag);
106  template <typename T> static T ATanpiImpl(T x, Arithmetic::IsFP16Type tag);
107  template <typename T> static T ATanpiImpl(T const& x, Arithmetic::IsBSType tag);
108 
109  template <typename T> static T ATan2piImpl(T y, T x, Arithmetic::IsFPType tag);
110  template <typename T> static T ATan2piImpl(T y, T x, Arithmetic::IsFP16Type tag);
111  template <typename T> static T ATan2piImpl(T const& y, T const& x, Arithmetic::IsBSType tag);
112 
113  template <typename T> static T CeilImpl(T x, Arithmetic::IsFPType tag);
114  template <typename T> static T CeilImpl(T x, Arithmetic::IsFP16Type tag);
115  template <typename T> static T CeilImpl(T const& x, Arithmetic::IsBSType tag);
116 
117  template <typename T> static T CosImpl(T x, Arithmetic::IsFPType tag);
118  template <typename T> static T CosImpl(T x, Arithmetic::IsFP16Type tag);
119  template <typename T> static T CosImpl(T const& x, Arithmetic::IsBSType tag);
120 
121  template <typename T> static T CoshImpl(T x, Arithmetic::IsFPType tag);
122  template <typename T> static T CoshImpl(T x, Arithmetic::IsFP16Type tag);
123  template <typename T> static T CoshImpl(T const& x, Arithmetic::IsBSType tag);
124 
125  template <typename T> static T CospiImpl(T x, Arithmetic::IsFPType tag);
126  template <typename T> static T CospiImpl(T x, Arithmetic::IsFP16Type tag);
127  template <typename T> static T CospiImpl(T const& x, Arithmetic::IsBSType tag);
128 
129  template <typename T> static T ExpImpl(T x, Arithmetic::IsFPType tag);
130  template <typename T> static T ExpImpl(T x, Arithmetic::IsFP16Type tag);
131  template <typename T> static T ExpImpl(T const& x, Arithmetic::IsBSType tag);
132 
133  template <typename T> static T Exp2Impl(T x, Arithmetic::IsFPType tag);
134  template <typename T> static T Exp2Impl(T x, Arithmetic::IsFP16Type tag);
135  template <typename T> static T Exp2Impl(T const& x, Arithmetic::IsBSType tag);
136 
137  template <typename T> static T Exp10Impl(T x, Arithmetic::IsFPType tag);
138  template <typename T> static T Exp10Impl(T x, Arithmetic::IsFP16Type tag);
139  template <typename T> static T Exp10Impl(T const& x, Arithmetic::IsBSType tag);
140 
141  template <typename T> static T FAbsImpl(T x, Arithmetic::IsFPType tag);
142  template <typename T> static T FAbsImpl(T x, Arithmetic::IsFP16Type tag);
143  template <typename T> static T FAbsImpl(T const& x, Arithmetic::IsBSType tag);
144 
145  template <typename T> static T FloorImpl(T x, Arithmetic::IsFPType tag);
146  template <typename T> static T FloorImpl(T x, Arithmetic::IsFP16Type tag);
147  template <typename T> static T FloorImpl(T const& x, Arithmetic::IsBSType tag);
148 
149  template <typename T> static T FModImpl(T x, T y, Arithmetic::IsFPType tag);
150  template <typename T> static T FModImpl(T x, T y, Arithmetic::IsFP16Type tag);
151  template <typename T> static T FModImpl(T const& x, T const& y, Arithmetic::IsBSType tag);
152 
153  template <typename T> static T InvSqrtImpl(T x, Arithmetic::IsFPType tag);
154  template <typename T> static T InvSqrtImpl(T x, Arithmetic::IsFP16Type tag);
155  template <typename T> static T InvSqrtImpl(T const& x, Arithmetic::IsBSType tag);
156 
157  template <typename T> static T LogImpl(T x, Arithmetic::IsFPType tag);
158  template <typename T> static T LogImpl(T x, Arithmetic::IsFP16Type tag);
159  template <typename T> static T LogImpl(T const& x, Arithmetic::IsBSType tag);
160 
161  template <typename T> static T Log2Impl(T x, Arithmetic::IsFPType tag);
162  template <typename T> static T Log2Impl(T x, Arithmetic::IsFP16Type tag);
163  template <typename T> static T Log2Impl(T const& x, Arithmetic::IsBSType tag);
164 
165  template <typename T> static T Log10Impl(T x, Arithmetic::IsFPType tag);
166  template <typename T> static T Log10Impl(T x, Arithmetic::IsFP16Type tag);
167  template <typename T> static T Log10Impl(T const& x, Arithmetic::IsBSType tag);
168 
169  template <typename T> static T PowImpl(T x, T y, Arithmetic::IsFPType tag);
170  template <typename T> static T PowImpl(T x, T y, Arithmetic::IsFP16Type tag);
171  template <typename T> static T PowImpl(T const& x, T const& y, Arithmetic::IsBSType tag);
172 
173  template <typename T> static T SinImpl(T x, Arithmetic::IsFPType tag);
174  template <typename T> static T SinImpl(T x, Arithmetic::IsFP16Type tag);
175  template <typename T> static T SinImpl(T const& x, Arithmetic::IsBSType tag);
176 
177  template <typename T> static T SinhImpl(T x, Arithmetic::IsFPType tag);
178  template <typename T> static T SinhImpl(T x, Arithmetic::IsFP16Type tag);
179  template <typename T> static T SinhImpl(T const& x, Arithmetic::IsBSType tag);
180 
181  template <typename T> static T SinpiImpl(T x, Arithmetic::IsFPType tag);
182  template <typename T> static T SinpiImpl(T x, Arithmetic::IsFP16Type tag);
183  template <typename T> static T SinpiImpl(T const& x, Arithmetic::IsBSType tag);
184 
185  template <typename T> static T SqrtImpl(T x, Arithmetic::IsFPType tag);
186  template <typename T> static T SqrtImpl(T x, Arithmetic::IsFP16Type tag);
187  template <typename T> static T SqrtImpl(T const& x, Arithmetic::IsBSType tag);
188 
189  template <typename T> static T TanImpl(T x, Arithmetic::IsFPType tag);
190  template <typename T> static T TanImpl(T x, Arithmetic::IsFP16Type tag);
191  template <typename T> static T TanImpl(T const& x, Arithmetic::IsBSType tag);
192 
193  template <typename T> static T TanhImpl(T x, Arithmetic::IsFPType tag);
194  template <typename T> static T TanhImpl(T x, Arithmetic::IsFP16Type tag);
195  template <typename T> static T TanhImpl(T const& x, Arithmetic::IsBSType tag);
196 
197  template <typename T> static T SignImpl(T x, Arithmetic::IsFPType tag);
198  template <typename T> static T SignImpl(T x, Arithmetic::IsFP16Type tag);
199  template <typename T> static T SignImpl(T const& x, Arithmetic::IsBSType tag);
200 
201  template <typename T> static int ISignImpl(T x, Arithmetic::IsFPType tag);
202  template <typename T> static int ISignImpl(T x, Arithmetic::IsFP16Type tag);
203  template <typename T> static int ISignImpl(T const& x, Arithmetic::IsBSType tag);
204 
205  template <typename T> static T SaturateImpl(T x, Arithmetic::IsFPType tag);
206  template <typename T> static T SaturateImpl(T x, Arithmetic::IsFP16Type tag);
207  template <typename T> static T SaturateImpl(T const& x, Arithmetic::IsBSType tag);
208 
209  template <typename T>
210  static unsigned int GetMaxBisectionsImpl(Arithmetic::IsFPType tag);
211 
212  template <typename T>
213  static unsigned int GetMaxBisectionsImpl(Arithmetic::IsFP16Type tag);
214 
215  template <typename T>
216  static unsigned int GetMaxBisectionsImpl(Arithmetic::IsBSType tag);
217 };
218 
219 
220 template <typename Real>
221 Real Function<Real>::ACos(Real const& x)
222 {
223  return ACosImpl<Real>(x, Arithmetic::WhichType<Real>());
224 }
225 
226 template <typename Real> template <typename T>
228 {
229  return acos(x);
230 }
231 
232 template <typename Real> template <typename T>
234 {
235  return (T)acos((float)x);
236 }
237 
238 template <typename Real> template <typename T>
240 {
241  return (T)acos((double)x);
242 }
243 
244 
245 
246 template <typename Real>
247 Real Function<Real>::ACosh(Real const& x)
248 {
249  return ACoshImpl<Real>(x, Arithmetic::WhichType<Real>());
250 }
251 
252 template <typename Real> template <typename T>
254 {
255  return log(x + sqrt(x * x - (Real)1));
256 }
257 
258 template <typename Real> template <typename T>
260 {
261  float y = (float)x;
262  return (T)log(y + sqrt(y * y - 1.0f));
263 }
264 
265 template <typename Real> template <typename T>
267 {
268  double y = (double)x;
269  return (T)log(y + sqrt(y * y - 1.0));
270 }
271 
272 
273 
274 template <typename Real>
275 Real Function<Real>::ASin(Real const& x)
276 {
277  return ASinImpl<Real>(x, Arithmetic::WhichType<Real>());
278 }
279 
280 template <typename Real> template <typename T>
282 {
283  return asin(x);
284 }
285 
286 template <typename Real> template <typename T>
288 {
289  return (T)asin((float)x);
290 }
291 
292 template <typename Real> template <typename T>
294 {
295  return (T)asin((double)x);
296 }
297 
298 
299 
300 template <typename Real>
301 Real Function<Real>::ASinh(Real const& x)
302 {
303  return ASinhImpl<Real>(x, Arithmetic::WhichType<Real>());
304 }
305 
306 template <typename Real> template <typename T>
308 {
309  return log(x + sqrt(x * x + (Real)1));
310 }
311 
312 template <typename Real> template <typename T>
314 {
315  float y = (float)x;
316  return (T)log(y + sqrt(y * y + 1.0f));
317 }
318 
319 template <typename Real> template <typename T>
321 {
322  double y = (double)x;
323  return (T)log(y + sqrt(y * y + 1.0));
324 }
325 
326 
327 
328 template <typename Real>
329 Real Function<Real>::ATan(Real const& x)
330 {
331  return ATanImpl<Real>(x, Arithmetic::WhichType<Real>());
332 }
333 
334 template <typename Real> template <typename T>
336 {
337  return atan(x);
338 }
339 
340 template <typename Real> template <typename T>
342 {
343  return (T)atan((float)x);
344 }
345 
346 template <typename Real> template <typename T>
348 {
349  return (T)atan((double)x);
350 }
351 
352 
353 
354 template <typename Real>
355 Real Function<Real>::ATanh(Real const& x)
356 {
357  return ATanhImpl<Real>(x, Arithmetic::WhichType<Real>());
358 }
359 
360 template <typename Real> template <typename T>
362 {
363  return log( ((Real)1 + x) / ((Real)1 - x) ) * (Real)0.5;
364 }
365 
366 template <typename Real> template <typename T>
368 {
369  float y = (float)x;
370  return (T)(log( (1.0f + y) / (1.0f - y) ) * 0.5f);
371 }
372 
373 template <typename Real> template <typename T>
375 {
376  double y = (double)x;
377  return (T)(log( (1.0 + y) / (1.0 - y) ) * 0.5);
378 }
379 
380 
381 
382 template <typename Real>
383 Real Function<Real>::ATan2(Real const& y, Real const& x)
384 {
385  return ATan2Impl<Real>(y, x, Arithmetic::WhichType<Real>());
386 }
387 
388 template <typename Real> template <typename T>
390 {
391  return atan2(y, x);
392 }
393 
394 template <typename Real> template <typename T>
396 {
397  return (T)atan2((float)y, (float)x);
398 }
399 
400 template <typename Real> template <typename T>
402 {
403  return (T)atan2((double)y, (double)x);
404 }
405 
406 
407 
408 template <typename Real>
409 Real Function<Real>::ATanpi(Real const& x)
410 {
411  return ATanpiImpl<Real>(x, Arithmetic::WhichType<Real>());
412 }
413 
414 template <typename Real> template <typename T>
416 {
417  return atan(x) * (Real)GTE_C_INV_PI;
418 }
419 
420 template <typename Real> template <typename T>
422 {
423  return (T)(atan((float)x) * (float)GTE_C_INV_PI);
424 }
425 
426 template <typename Real> template <typename T>
428 {
429  return (T)(atan((double)x) * GTE_C_INV_PI);
430 }
431 
432 
433 
434 template <typename Real>
435 Real Function<Real>::ATan2pi(Real const& y, Real const& x)
436 {
437  return ATan2piImpl<Real>(y, x, Arithmetic::WhichType<Real>());
438 }
439 
440 template <typename Real> template <typename T>
442 {
443  return atan2(y, x) * (Real)GTE_C_INV_PI;
444 }
445 
446 template <typename Real> template <typename T>
448 {
449  return (T)(atan2((float)y, (float)x) * (float)GTE_C_INV_PI);
450 }
451 
452 template <typename Real> template <typename T>
454 {
455  return (T)(atan2((double)y, (double)x) * GTE_C_INV_PI);
456 }
457 
458 
459 
460 template <typename Real>
461 Real Function<Real>::Ceil(Real const& x)
462 {
463  return CeilImpl<Real>(x, Arithmetic::WhichType<Real>());
464 }
465 
466 template <typename Real> template <typename T>
468 {
469  return ceil(x);
470 }
471 
472 template <typename Real> template <typename T>
474 {
475  return (T)ceil((float)x);
476 }
477 
478 template <typename Real> template <typename T>
480 {
481  return (T)ceil((double)x);
482 }
483 
484 
485 
486 template <typename Real>
487 Real Function<Real>::Cos(Real const& x)
488 {
489  return CosImpl<Real>(x, Arithmetic::WhichType<Real>());
490 }
491 
492 template <typename Real> template <typename T>
494 {
495  return cos(x);
496 }
497 
498 template <typename Real> template <typename T>
500 {
501  return (T)cos((float)x);
502 }
503 
504 template <typename Real> template <typename T>
506 {
507  return (T)cos((double)x);
508 }
509 
510 
511 
512 template <typename Real>
513 Real Function<Real>::Cosh(Real const& x)
514 {
515  return CoshImpl<Real>(x, Arithmetic::WhichType<Real>());
516 }
517 
518 template <typename Real> template <typename T>
520 {
521  return cosh(x);
522 }
523 
524 template <typename Real> template <typename T>
526 {
527  return (T)cosh((float)x);
528 }
529 
530 template <typename Real> template <typename T>
532 {
533  return (T)cosh((double)x);
534 }
535 
536 
537 
538 template <typename Real>
539 Real Function<Real>::Cospi(Real const& x)
540 {
541  return CospiImpl<Real>(x, Arithmetic::WhichType<Real>());
542 }
543 
544 template <typename Real> template <typename T>
546 {
547  return cos(x * (Real)GTE_C_PI);
548 }
549 
550 template <typename Real> template <typename T>
552 {
553  return (T)cos((float)x * (float)GTE_C_PI);
554 }
555 
556 template <typename Real> template <typename T>
558 {
559  return (T)cos((double)(x * (T)GTE_C_PI));
560 }
561 
562 
563 
564 template <typename Real>
565 Real Function<Real>::Exp(Real const& x)
566 {
567  return ExpImpl<Real>(x, Arithmetic::WhichType<Real>());
568 }
569 
570 template <typename Real> template <typename T>
572 {
573  return exp(x);
574 }
575 
576 template <typename Real> template <typename T>
578 {
579  return (T)exp((float)x);
580 }
581 
582 template <typename Real> template <typename T>
584 {
585  return (T)exp((double)x);
586 }
587 
588 
589 
590 template <typename Real>
591 Real Function<Real>::Exp2(Real const& x)
592 {
593  return Exp2Impl<Real>(x, Arithmetic::WhichType<Real>());
594 }
595 
596 template <typename Real> template <typename T>
598 {
599  return exp(x * (Real)GTE_C_LN_2);
600 }
601 
602 template <typename Real> template <typename T>
604 {
605  return (T)exp((float)x * (float)GTE_C_LN_2);
606 }
607 
608 template <typename Real> template <typename T>
610 {
611  return (T)exp((double)(x * (T)GTE_C_LN_2));
612 }
613 
614 
615 
616 template <typename Real>
617 Real Function<Real>::Exp10(Real const& x)
618 {
619  return Exp10Impl<Real>(x, Arithmetic::WhichType<Real>());
620 }
621 
622 template <typename Real> template <typename T>
624 {
625  return exp(x * (Real)GTE_C_LN_10);
626 }
627 
628 template <typename Real> template <typename T>
630 {
631  return (T)exp((float)x * (float)GTE_C_LN_10);
632 }
633 
634 template <typename Real> template <typename T>
636 {
637  return (T)exp((double)(x * (T)GTE_C_LN_10));
638 }
639 
640 
641 
642 template <typename Real>
643 Real Function<Real>::FAbs(Real const& x)
644 {
645  return FAbsImpl<Real>(x, Arithmetic::WhichType<Real>());
646 }
647 
648 template <typename Real> template <typename T>
650 {
651  return fabs(x);
652 }
653 
654 template <typename Real> template <typename T>
656 {
657  return (Real)fabs((float)x);
658 }
659 
660 template <typename Real> template <typename T>
662 {
663  return (x.GetSign() >= 0 ? x : -x);
664 }
665 
666 
667 
668 template <typename Real>
669 Real Function<Real>::Floor(Real const& x)
670 {
671  return FloorImpl<Real>(x, Arithmetic::WhichType<Real>());
672 }
673 
674 template <typename Real> template <typename T>
676 {
677  return floor(x);
678 }
679 
680 template <typename Real> template <typename T>
682 {
683  return (T)floor((float)x);
684 }
685 
686 template <typename Real> template <typename T>
688 {
689  return (T)floor((double)x);
690 }
691 
692 
693 
694 template <typename Real>
695 Real Function<Real>::FMod(Real const& x, Real const& y)
696 {
697  return FModImpl<Real>(x, y, Arithmetic::WhichType<Real>());
698 }
699 
700 template <typename Real> template <typename T>
702 {
703  return fmod(x, y);
704 }
705 
706 template <typename Real> template <typename T>
708 {
709  return (T)fmod((float)x, (float)y);
710 }
711 
712 template <typename Real> template <typename T>
714 {
715  return (T)fmod((double)x, (double)y);
716 }
717 
718 
719 
720 template <typename Real>
721 Real Function<Real>::InvSqrt(Real const& x)
722 {
723  return InvSqrtImpl<Real>(x, Arithmetic::WhichType<Real>());
724 }
725 
726 template <typename Real> template <typename T>
728 {
729  return ((T)1) / sqrt(x);
730 }
731 
732 template <typename Real> template <typename T>
734 {
735  return (T)(1.0f / sqrt((float)x));
736 }
737 
738 template <typename Real> template <typename T>
740 {
741  return (T)(1.0 / sqrt((double)x));
742 }
743 
744 
745 
746 template <typename Real>
747 Real Function<Real>::Log(Real const& x)
748 {
749  return LogImpl<Real>(x, Arithmetic::WhichType<Real>());
750 }
751 
752 template <typename Real> template <typename T>
754 {
755  return log(x);
756 }
757 
758 template <typename Real> template <typename T>
760 {
761  return (T)log((float)x);
762 }
763 
764 template <typename Real> template <typename T>
766 {
767  return (T)log((double)x);
768 }
769 
770 
771 
772 template <typename Real>
773 Real Function<Real>::Log2(Real const& x)
774 {
775  return Log2Impl<Real>(x, Arithmetic::WhichType<Real>());
776 }
777 
778 template <typename Real> template <typename T>
780 {
781  return log(x) * (Real)GTE_C_INV_LN_2;
782 }
783 
784 template <typename Real> template <typename T>
786 {
787  return (T)(log((float)x) * (float)GTE_C_INV_LN_2);
788 }
789 
790 template <typename Real> template <typename T>
792 {
793  return (T)(log((double)x) * GTE_C_INV_LN_2);
794 }
795 
796 
797 
798 template <typename Real>
799 Real Function<Real>::Log10(Real const& x)
800 {
801  return Log10Impl<Real>(x, Arithmetic::WhichType<Real>());
802 }
803 
804 template <typename Real> template <typename T>
806 {
807  return log10(x);
808 }
809 
810 template <typename Real> template <typename T>
812 {
813  return (T)log10((float)x);
814 }
815 
816 template <typename Real> template <typename T>
818 {
819  return (T)log10((double)x);
820 }
821 
822 
823 
824 template <typename Real>
825 Real Function<Real>::Pow(Real const& x, Real const& y)
826 {
827  return PowImpl<Real>(x, y, Arithmetic::WhichType<Real>());
828 }
829 
830 template <typename Real> template <typename T>
832 {
833  return pow(x, y);
834 }
835 
836 template <typename Real> template <typename T>
838 {
839  return (T)pow((float)x, (float)y);
840 }
841 
842 template <typename Real> template <typename T>
844 {
845  return (T)pow((double)x, (double)y);
846 }
847 
848 
849 
850 template <typename Real>
851 Real Function<Real>::Sin(Real const& x)
852 {
853  return SinImpl<Real>(x, Arithmetic::WhichType<Real>());
854 }
855 
856 template <typename Real> template <typename T>
858 {
859  return sin(x);
860 }
861 
862 template <typename Real> template <typename T>
864 {
865  return (T)sin((float)x);
866 }
867 
868 template <typename Real> template <typename T>
870 {
871  return (T)sin((double)x);
872 }
873 
874 
875 
876 template <typename Real>
877 Real Function<Real>::Sinh(Real const& x)
878 {
879  return SinhImpl<Real>(x, Arithmetic::WhichType<Real>());
880 }
881 
882 template <typename Real> template <typename T>
884 {
885  return sinh(x);
886 }
887 
888 template <typename Real> template <typename T>
890 {
891  return (T)sinh((float)x);
892 }
893 
894 template <typename Real> template <typename T>
896 {
897  return (T)sinh((double)x);
898 }
899 
900 
901 
902 template <typename Real>
903 Real Function<Real>::Sinpi(Real const& x)
904 {
905  return SinpiImpl<Real>(x, Arithmetic::WhichType<Real>());
906 }
907 
908 template <typename Real> template <typename T>
910 {
911  return sin(x * (Real)GTE_C_PI);
912 }
913 
914 template <typename Real> template <typename T>
916 {
917  return (T)sin((float)x * (float)GTE_C_PI);
918 }
919 
920 template <typename Real> template <typename T>
922 {
923  return (T)sin((double)(x * (T)GTE_C_PI));
924 }
925 
926 
927 
928 template <typename Real>
929 Real Function<Real>::Sqr(Real const& x)
930 {
931  return x * x;
932 }
933 
934 
935 
936 template <typename Real>
937 Real Function<Real>::Sqrt(Real const& x)
938 {
939  return SqrtImpl<Real>(x, Arithmetic::WhichType<Real>());
940 }
941 
942 template <typename Real> template <typename T>
944 {
945  return sqrt(x);
946 }
947 
948 template <typename Real> template <typename T>
950 {
951  return (T)sqrt((float)x);
952 }
953 
954 template <typename Real> template <typename T>
956 {
957  return (T)sqrt((double)x);
958 }
959 
960 
961 
962 template <typename Real>
963 Real Function<Real>::Tan(Real const& x)
964 {
965  return TanImpl<Real>(x, Arithmetic::WhichType<Real>());
966 }
967 
968 template <typename Real> template <typename T>
970 {
971  return tan(x);
972 }
973 
974 template <typename Real> template <typename T>
976 {
977  return (T)tan((float)x);
978 }
979 
980 template <typename Real> template <typename T>
982 {
983  return (T)tan((double)x);
984 }
985 
986 
987 
988 template <typename Real>
989 Real Function<Real>::Tanh(Real const& x)
990 {
991  return TanhImpl<Real>(x, Arithmetic::WhichType<Real>());
992 }
993 
994 template <typename Real> template <typename T>
996 {
997  return tanh(x);
998 }
999 
1000 template <typename Real> template <typename T>
1002 {
1003  return (T)tanh((float)x);
1004 }
1005 
1006 template <typename Real> template <typename T>
1008 {
1009  return (T)tanh((double)x);
1010 }
1011 
1012 
1013 
1014 template <typename Real>
1015 Real Function<Real>::Sign(Real const& x)
1016 {
1017  return SignImpl<Real>(x, Arithmetic::WhichType<Real>());
1018 }
1019 
1020 template <typename Real> template <typename T>
1022 {
1023  return (x > (Real)0 ? (Real)1 : (x < (Real)0 ? (Real)-1 : (Real)0));
1024 }
1025 
1026 template <typename Real> template <typename T>
1028 {
1029  float y = (Real)x;
1030  return (y > 0.0f ? 1.0f : (y < 0.0f ? -1.0f : 0.0f));
1031 }
1032 
1033 template <typename Real> template <typename T>
1035 {
1036  return (Real)x.GetSign();
1037 }
1038 
1039 
1040 
1041 template <typename Real>
1042 int Function<Real>::ISign(Real const& x)
1043 {
1044  return ISignImpl<Real>(x, Arithmetic::WhichType<Real>());
1045 }
1046 
1047 template <typename Real> template <typename T>
1049 {
1050  return (x > (Real)0 ? 1 : (x < (Real)0 ? -1 : 0));
1051 }
1052 
1053 template <typename Real> template <typename T>
1055 {
1056  float y = (Real)x;
1057  return (y > 0.0f ? 1 : (y < 0 ? -1 : 0));
1058 }
1059 
1060 template <typename Real> template <typename T>
1062 {
1063  return x.GetSign();
1064 }
1065 
1066 
1067 
1068 template <typename Real>
1069 Real Function<Real>::Clamp(Real const& x, Real const& min, Real const& max)
1070 {
1071  return (x <= min ? min : (x >= max ? max : x));
1072 }
1073 
1074 template <typename Real>
1075 Real Function<Real>::Saturate(Real const& x)
1076 {
1077  return SaturateImpl<Real>(x, Arithmetic::WhichType<Real>());
1078 }
1079 
1080 template <typename Real> template <typename T>
1082 {
1083  return (x <= (Real)0 ? (Real)0 : (x >= (Real)1 ? (Real)1 : x));
1084 }
1085 
1086 template <typename Real> template <typename T>
1088 {
1089  float y = (float)x;
1090  return (y <= 0.0f ? 0.0f : (y >= 1.0f ? 1.0f : y));
1091 }
1092 
1093 template <typename Real> template <typename T>
1095 {
1096  Real const zero(0), one(1);
1097  return (x <= zero ? zero : (x >= one ? one : x));
1098 }
1099 
1100 
1101 
1102 template <typename Real>
1104 {
1105  return GetMaxBisectionsImpl<Real>(Arithmetic::WhichType<Real>());
1106 }
1107 
1108 template <typename Real> template <typename T>
1110 {
1111  return (unsigned int)(3 + std::numeric_limits<Real>::digits -
1112  std::numeric_limits<Real>::min_exponent);
1113 }
1114 
1115 template <typename Real> template <typename T>
1117 {
1118  // std::numeric_limits<IEEEBinary16>::digits = 11
1119  // std::numeric_limits<IEEEBinary16>::min_exponent = -13
1120  // 27 = 3 + digits - min_exponent
1121  return 27;
1122 }
1123 
1124 template <typename Real> template <typename T>
1126 {
1127  return std::numeric_limits<unsigned int>::max();
1128 }
1129 
1130 
1131 }
static Real Saturate(Real const &x)
#define GTE_C_INV_LN_2
Definition: GteConstants.h:33
static Real Exp2(Real const &x)
Definition: GteFunctions.h:591
static T Exp10Impl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:623
static Real Cosh(Real const &x)
Definition: GteFunctions.h:513
static T CeilImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:467
static Real ACosh(Real const &x)
Definition: GteFunctions.h:247
static T ACosImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:227
std::integral_constant< Type, IS_FP16 > IsFP16Type
Definition: GteArithmetic.h:38
static Real Cos(Real const &x)
Definition: GteFunctions.h:487
static int ISignImpl(T x, Arithmetic::IsFPType tag)
static Real Sign(Real const &x)
static Real ASinh(Real const &x)
Definition: GteFunctions.h:301
static Real Clamp(Real const &x, Real const &min, Real const &max)
static T Log2Impl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:779
static T FModImpl(T x, T y, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:701
static T FloorImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:675
static Real Tanh(Real const &x)
Definition: GteFunctions.h:989
static T SaturateImpl(T x, Arithmetic::IsFPType tag)
static T ATan2Impl(T y, T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:389
static T ATanhImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:361
static Real ATanh(Real const &x)
Definition: GteFunctions.h:355
static Real Sinh(Real const &x)
Definition: GteFunctions.h:877
static unsigned int GetMaxBisections()
static T InvSqrtImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:727
static Real Sqr(Real const &x)
Definition: GteFunctions.h:929
static T SinpiImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:909
static Real Sqrt(Real const &x)
Definition: GteFunctions.h:937
static Real Exp10(Real const &x)
Definition: GteFunctions.h:617
static Real Ceil(Real const &x)
Definition: GteFunctions.h:461
GLint GLenum GLint x
Definition: glcorearb.h:404
static T ATanImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:335
static T SinImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:857
static Real ASin(Real const &x)
Definition: GteFunctions.h:275
static Real ATan2pi(Real const &y, Real const &x)
Definition: GteFunctions.h:435
static T CospiImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:545
static Real FAbs(Real const &x)
Definition: GteFunctions.h:643
#define GTE_C_PI
Definition: GteConstants.h:17
static T PowImpl(T x, T y, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:831
static unsigned int GetMaxBisectionsImpl(Arithmetic::IsFPType tag)
#define GTE_C_LN_2
Definition: GteConstants.h:32
static Real ACos(Real const &x)
Definition: GteFunctions.h:221
static Real Exp(Real const &x)
Definition: GteFunctions.h:565
static T ACoshImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:253
static T CosImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:493
static T FAbsImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:649
static Real Pow(Real const &x, Real const &y)
Definition: GteFunctions.h:825
std::integral_constant< Type, IS_FLOATING_POINT > IsFPType
Definition: GteArithmetic.h:37
static Real Log10(Real const &x)
Definition: GteFunctions.h:799
static Real Sinpi(Real const &x)
Definition: GteFunctions.h:903
static T LogImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:753
static Real ATanpi(Real const &x)
Definition: GteFunctions.h:409
static Real Cospi(Real const &x)
Definition: GteFunctions.h:539
static Real Sin(Real const &x)
Definition: GteFunctions.h:851
static Real ATan2(Real const &y, Real const &x)
Definition: GteFunctions.h:383
static T CoshImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:519
static Real ATan(Real const &x)
Definition: GteFunctions.h:329
static T SqrtImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:943
std::integral_constant< Type, IS_BINARY_SCIENTIFIC > IsBSType
Definition: GteArithmetic.h:39
static T ExpImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:571
static T TanhImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:995
#define GTE_C_LN_10
Definition: GteConstants.h:34
static T ASinImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:281
GLfloat f
Definition: glcorearb.h:1921
static int ISign(Real const &x)
static T ATanpiImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:415
static Real Log2(Real const &x)
Definition: GteFunctions.h:773
static T SignImpl(T x, Arithmetic::IsFPType tag)
static T ATan2piImpl(T y, T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:441
static T ASinhImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:307
static T Exp2Impl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:597
static Real Log(Real const &x)
Definition: GteFunctions.h:747
#define GTE_C_INV_PI
Definition: GteConstants.h:21
static Real InvSqrt(Real const &x)
Definition: GteFunctions.h:721
static T SinhImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:883
static T TanImpl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:969
GLint y
Definition: glcorearb.h:98
static Real Floor(Real const &x)
Definition: GteFunctions.h:669
static Real Tan(Real const &x)
Definition: GteFunctions.h:963
static T Log10Impl(T x, Arithmetic::IsFPType tag)
Definition: GteFunctions.h:805
static Real FMod(Real const &x, Real const &y)
Definition: GteFunctions.h:695


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59