math.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*-------------------------------------------------------------------------
  2. math.h: Floating point math function declarations
  3. Copyright (C) 2001, Jesus Calvino-Fraga, jesusc@ieee.org
  4. This library is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this library; see the file COPYING. If not, write to the
  14. Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  15. MA 02110-1301, USA.
  16. As a special exception, if you link this library with other files,
  17. some of which are compiled with SDCC, to produce an executable,
  18. this library does not by itself cause the resulting executable to
  19. be covered by the GNU General Public License. This exception does
  20. not however invalidate any other reasons why the executable file
  21. might be covered by the GNU General Public License.
  22. -------------------------------------------------------------------------*/
  23. /* Version 1.0 - Initial release */
  24. #ifndef _INC_MATH
  25. #define _INC_MATH
  26. #define HUGE_VALF 3.402823466e+38
  27. #define PI 3.1415926536
  28. #define TWO_PI 6.2831853071
  29. #define HALF_PI 1.5707963268
  30. #define QUART_PI 0.7853981634
  31. #define iPI 0.3183098862
  32. #define iTWO_PI 0.1591549431
  33. #define TWO_O_PI 0.6366197724
  34. /* EPS=B**(-t/2), where B is the radix of the floating-point representation
  35. and there are t base-B digits in the significand. Therefore, for floats
  36. EPS=2**(-12). Also define EPS2=EPS*EPS. */
  37. #define EPS 244.14062E-6
  38. #define EPS2 59.6046E-9
  39. union float_long
  40. {
  41. float f;
  42. long l;
  43. };
  44. #if defined(__SDCC_MATH_LIB) && defined(__SDCC_mcs51) && !defined(__SDCC_USE_XSTACK) && !defined(__SDCC_STACK_AUTO) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
  45. /* Compile the mcs51 assembly version only when all these
  46. conditions are met. Since not all the functions are
  47. reentrant, do not compile with --stack-auto is used. */
  48. #define MATH_ASM_MCS51
  49. #endif
  50. /* Functions on the z80 & gbz80 are always reentrant and so the "reentrant" */
  51. /* keyword is not defined. */
  52. #if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_r4k) || defined(__SDCC_gbz80)
  53. #define _FLOAT_FUNC_REENTRANT
  54. #else
  55. #define _FLOAT_FUNC_REENTRANT __reentrant
  56. #endif
  57. /**********************************************
  58. * Prototypes for float ANSI C math functions *
  59. **********************************************/
  60. /* Trigonometric functions */
  61. float sinf(const float x) _FLOAT_FUNC_REENTRANT;
  62. float cosf(const float x) _FLOAT_FUNC_REENTRANT;
  63. float tanf(const float x) _FLOAT_FUNC_REENTRANT;
  64. float cotf(const float x) _FLOAT_FUNC_REENTRANT;
  65. float asinf(const float x) _FLOAT_FUNC_REENTRANT;
  66. float acosf(const float x) _FLOAT_FUNC_REENTRANT;
  67. float atanf(const float x) _FLOAT_FUNC_REENTRANT;
  68. float atan2f(const float x, const float y);
  69. /* Hyperbolic functions */
  70. float sinhf(const float x) _FLOAT_FUNC_REENTRANT;
  71. float coshf(const float x) _FLOAT_FUNC_REENTRANT;
  72. float tanhf(const float x) _FLOAT_FUNC_REENTRANT;
  73. /* Exponential, logarithmic and power functions */
  74. float expf(const float x);
  75. float logf(const float x) _FLOAT_FUNC_REENTRANT;
  76. float log10f(const float x) _FLOAT_FUNC_REENTRANT;
  77. float powf(const float x, const float y);
  78. float sqrtf(const float a) _FLOAT_FUNC_REENTRANT;
  79. /* Nearest integer, absolute value, and remainder functions */
  80. float fabsf(const float x) _FLOAT_FUNC_REENTRANT;
  81. float frexpf(const float x, int *pw2);
  82. float ldexpf(const float x, const int pw2);
  83. float ceilf(float x) _FLOAT_FUNC_REENTRANT;
  84. float floorf(float x) _FLOAT_FUNC_REENTRANT;
  85. float modff(float x, float * y);
  86. #endif /* _INC_MATH */