libm.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 libavutil/libm.h
  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_EXP2
  28. #undef exp2
  29. #define exp2(x) exp((x) * 0.693147180559945)
  30. #endif /* HAVE_EXP2 */
  31. #if !HAVE_EXP2F
  32. #undef exp2f
  33. #define exp2f(x) ((float)exp2(x))
  34. #endif /* HAVE_EXP2F */
  35. #if !HAVE_LLRINT
  36. #undef llrint
  37. #define llrint(x) ((long long)rint(x))
  38. #endif /* HAVE_LLRINT */
  39. #if !HAVE_LOG2
  40. #undef log2
  41. #define log2(x) (log(x) * 1.44269504088896340736)
  42. #endif /* HAVE_LOG2 */
  43. #if !HAVE_LOG2F
  44. #undef log2f
  45. #define log2f(x) ((float)log2(x))
  46. #endif /* HAVE_LOG2F */
  47. #if !HAVE_LRINT
  48. static av_always_inline av_const long int lrint(double x)
  49. {
  50. return rint(x);
  51. }
  52. #endif /* HAVE_LRINT */
  53. #if !HAVE_LRINTF
  54. static av_always_inline av_const long int lrintf(float x)
  55. {
  56. return (int)(rint(x));
  57. }
  58. #endif /* HAVE_LRINTF */
  59. #if !HAVE_ROUND
  60. static av_always_inline av_const double round(double x)
  61. {
  62. return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
  63. }
  64. #endif /* HAVE_ROUND */
  65. #if !HAVE_ROUNDF
  66. static av_always_inline av_const float roundf(float x)
  67. {
  68. return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
  69. }
  70. #endif /* HAVE_ROUNDF */
  71. #if !HAVE_TRUNCF
  72. static av_always_inline av_const float truncf(float x)
  73. {
  74. return (x > 0) ? floor(x) : ceil(x);
  75. }
  76. #endif /* HAVE_TRUNCF */
  77. #endif /* AVUTIL_LIBM_H */