libm.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file
  20. * Replacements for frequently missing libm functions
  21. */
  22. #ifndef AVUTIL_LIBM_H
  23. #define AVUTIL_LIBM_H
  24. #include <math.h>
  25. #include "config.h"
  26. #include "attributes.h"
  27. #if !HAVE_CBRTF
  28. #undef cbrtf
  29. #define cbrtf(x) powf(x, 1.0/3.0)
  30. #endif /* HAVE_CBRTF */
  31. #if !HAVE_EXP2
  32. #undef exp2
  33. #define exp2(x) exp((x) * 0.693147180559945)
  34. #endif /* HAVE_EXP2 */
  35. #if !HAVE_EXP2F
  36. #undef exp2f
  37. #define exp2f(x) ((float)exp2(x))
  38. #endif /* HAVE_EXP2F */
  39. #if !HAVE_LLRINT
  40. #undef llrint
  41. #define llrint(x) ((long long)rint(x))
  42. #endif /* HAVE_LLRINT */
  43. #if !HAVE_LLRINTF
  44. #undef llrintf
  45. #define llrintf(x) ((long long)rint(x))
  46. #endif /* HAVE_LLRINT */
  47. #if !HAVE_LOG2
  48. #undef log2
  49. #define log2(x) (log(x) * 1.44269504088896340736)
  50. #endif /* HAVE_LOG2 */
  51. #if !HAVE_LOG2F
  52. #undef log2f
  53. #define log2f(x) ((float)log2(x))
  54. #endif /* HAVE_LOG2F */
  55. #if !HAVE_LRINT
  56. static av_always_inline av_const long int lrint(double x)
  57. {
  58. return rint(x);
  59. }
  60. #endif /* HAVE_LRINT */
  61. #if !HAVE_LRINTF
  62. static av_always_inline av_const long int lrintf(float x)
  63. {
  64. return (int)(rint(x));
  65. }
  66. #endif /* HAVE_LRINTF */
  67. #if !HAVE_ROUND
  68. static av_always_inline av_const double round(double x)
  69. {
  70. return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
  71. }
  72. #endif /* HAVE_ROUND */
  73. #if !HAVE_ROUNDF
  74. static av_always_inline av_const float roundf(float x)
  75. {
  76. return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
  77. }
  78. #endif /* HAVE_ROUNDF */
  79. #if !HAVE_TRUNC
  80. static av_always_inline av_const double trunc(double x)
  81. {
  82. return (x > 0) ? floor(x) : ceil(x);
  83. }
  84. #endif /* HAVE_TRUNC */
  85. #if !HAVE_TRUNCF
  86. static av_always_inline av_const float truncf(float x)
  87. {
  88. return (x > 0) ? floor(x) : ceil(x);
  89. }
  90. #endif /* HAVE_TRUNCF */
  91. #endif /* AVUTIL_LIBM_H */