You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.5KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; 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. static av_always_inline float cbrtf(float x)
  29. {
  30. return x < 0 ? -powf(-x, 1.0 / 3.0) : powf(x, 1.0 / 3.0);
  31. }
  32. #endif
  33. #if !HAVE_EXP2
  34. #undef exp2
  35. #define exp2(x) exp((x) * 0.693147180559945)
  36. #endif /* HAVE_EXP2 */
  37. #if !HAVE_EXP2F
  38. #undef exp2f
  39. #define exp2f(x) ((float)exp2(x))
  40. #endif /* HAVE_EXP2F */
  41. #if !HAVE_LLRINT
  42. #undef llrint
  43. #define llrint(x) ((long long)rint(x))
  44. #endif /* HAVE_LLRINT */
  45. #if !HAVE_LLRINTF
  46. #undef llrintf
  47. #define llrintf(x) ((long long)rint(x))
  48. #endif /* HAVE_LLRINT */
  49. #if !HAVE_LOG2
  50. #undef log2
  51. #define log2(x) (log(x) * 1.44269504088896340736)
  52. #endif /* HAVE_LOG2 */
  53. #if !HAVE_LOG2F
  54. #undef log2f
  55. #define log2f(x) ((float)log2(x))
  56. #endif /* HAVE_LOG2F */
  57. #if !HAVE_LRINT
  58. static av_always_inline av_const long int lrint(double x)
  59. {
  60. return rint(x);
  61. }
  62. #endif /* HAVE_LRINT */
  63. #if !HAVE_LRINTF
  64. static av_always_inline av_const long int lrintf(float x)
  65. {
  66. return (int)(rint(x));
  67. }
  68. #endif /* HAVE_LRINTF */
  69. #if !HAVE_ROUND
  70. static av_always_inline av_const double round(double x)
  71. {
  72. return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
  73. }
  74. #endif /* HAVE_ROUND */
  75. #if !HAVE_ROUNDF
  76. static av_always_inline av_const float roundf(float x)
  77. {
  78. return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
  79. }
  80. #endif /* HAVE_ROUNDF */
  81. #if !HAVE_TRUNC
  82. static av_always_inline av_const double trunc(double x)
  83. {
  84. return (x > 0) ? floor(x) : ceil(x);
  85. }
  86. #endif /* HAVE_TRUNC */
  87. #if !HAVE_TRUNCF
  88. static av_always_inline av_const float truncf(float x)
  89. {
  90. return (x > 0) ? floor(x) : ceil(x);
  91. }
  92. #endif /* HAVE_TRUNCF */
  93. #endif /* AVUTIL_LIBM_H */