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.

132 lines
2.9KB

  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. #include "intfloat.h"
  28. #if !HAVE_CBRTF
  29. static av_always_inline float cbrtf(float x)
  30. {
  31. return x < 0 ? -powf(-x, 1.0 / 3.0) : powf(x, 1.0 / 3.0);
  32. }
  33. #endif
  34. #if !HAVE_EXP2
  35. #undef exp2
  36. #define exp2(x) exp((x) * 0.693147180559945)
  37. #endif /* HAVE_EXP2 */
  38. #if !HAVE_EXP2F
  39. #undef exp2f
  40. #define exp2f(x) ((float)exp2(x))
  41. #endif /* HAVE_EXP2F */
  42. #if !HAVE_ISINF
  43. static av_always_inline av_const int isinf(float x)
  44. {
  45. uint32_t v = av_float2int(x);
  46. if ((v & 0x7f800000) != 0x7f800000)
  47. return 0;
  48. return !(v & 0x007fffff);
  49. }
  50. #endif /* HAVE_ISINF */
  51. #if !HAVE_ISNAN
  52. static av_always_inline av_const int isnan(float x)
  53. {
  54. uint32_t v = av_float2int(x);
  55. if ((v & 0x7f800000) != 0x7f800000)
  56. return 0;
  57. return v & 0x007fffff;
  58. }
  59. #endif /* HAVE_ISNAN */
  60. #if !HAVE_LLRINT
  61. #undef llrint
  62. #define llrint(x) ((long long)rint(x))
  63. #endif /* HAVE_LLRINT */
  64. #if !HAVE_LLRINTF
  65. #undef llrintf
  66. #define llrintf(x) ((long long)rint(x))
  67. #endif /* HAVE_LLRINT */
  68. #if !HAVE_LOG2
  69. #undef log2
  70. #define log2(x) (log(x) * 1.44269504088896340736)
  71. #endif /* HAVE_LOG2 */
  72. #if !HAVE_LOG2F
  73. #undef log2f
  74. #define log2f(x) ((float)log2(x))
  75. #endif /* HAVE_LOG2F */
  76. #if !HAVE_LRINT
  77. static av_always_inline av_const long int lrint(double x)
  78. {
  79. return rint(x);
  80. }
  81. #endif /* HAVE_LRINT */
  82. #if !HAVE_LRINTF
  83. static av_always_inline av_const long int lrintf(float x)
  84. {
  85. return (int)(rint(x));
  86. }
  87. #endif /* HAVE_LRINTF */
  88. #if !HAVE_ROUND
  89. static av_always_inline av_const double round(double x)
  90. {
  91. return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
  92. }
  93. #endif /* HAVE_ROUND */
  94. #if !HAVE_ROUNDF
  95. static av_always_inline av_const float roundf(float x)
  96. {
  97. return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
  98. }
  99. #endif /* HAVE_ROUNDF */
  100. #if !HAVE_TRUNC
  101. static av_always_inline av_const double trunc(double x)
  102. {
  103. return (x > 0) ? floor(x) : ceil(x);
  104. }
  105. #endif /* HAVE_TRUNC */
  106. #if !HAVE_TRUNCF
  107. static av_always_inline av_const float truncf(float x)
  108. {
  109. return (x > 0) ? floor(x) : ceil(x);
  110. }
  111. #endif /* HAVE_TRUNCF */
  112. #endif /* AVUTIL_LIBM_H */