sundials_types.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * -----------------------------------------------------------------
  3. * $Revision: 4378 $
  4. * $Date: 2015-02-19 10:55:14 -0800 (Thu, 19 Feb 2015) $
  5. * -----------------------------------------------------------------
  6. * Programmer(s): Scott Cohen, Alan Hindmarsh, Radu Serban, and
  7. * Aaron Collier @ LLNL
  8. * -----------------------------------------------------------------
  9. * Copyright (c) 2002, The Regents of the University of California.
  10. * Produced at the Lawrence Livermore National Laboratory.
  11. * All rights reserved.
  12. * For details, see the LICENSE file.
  13. *------------------------------------------------------------------
  14. * This header file exports two types: realtype and booleantype,
  15. * as well as the constants TRUE and FALSE.
  16. *
  17. * Users should include the header file sundials_types.h in every
  18. * program file and use the exported name realtype instead of
  19. * float, double or long double.
  20. *
  21. * The constants SUNDIALS_SINGLE_PRECISION, SUNDIALS_DOUBLE_PRECISION
  22. * and SUNDIALS_LONG_DOUBLE_PRECISION indicate the underlying data
  23. * type of realtype. It is set at the configuration stage.
  24. *
  25. * The legal types for realtype are float, double and long double.
  26. *
  27. * The macro RCONST gives the user a convenient way to define
  28. * real-valued constants. To use the constant 1.0, for example,
  29. * the user should write the following:
  30. *
  31. * #define ONE RCONST(1.0)
  32. *
  33. * If realtype is defined as a double, then RCONST(1.0) expands
  34. * to 1.0. If realtype is defined as a float, then RCONST(1.0)
  35. * expands to 1.0F. If realtype is defined as a long double,
  36. * then RCONST(1.0) expands to 1.0L. There is never a need to
  37. * explicitly cast 1.0 to (realtype).
  38. *------------------------------------------------------------------
  39. */
  40. #ifndef _SUNDIALSTYPES_H
  41. #define _SUNDIALSTYPES_H
  42. #ifndef _SUNDIALS_CONFIG_H
  43. #define _SUNDIALS_CONFIG_H
  44. #include <sundials/sundials_config.h>
  45. #endif
  46. #include <float.h>
  47. #ifdef __cplusplus /* wrapper to enable C++ usage */
  48. extern "C" {
  49. #endif
  50. /*
  51. *------------------------------------------------------------------
  52. * Type realtype
  53. * Macro RCONST
  54. * Constants BIG_REAL, SMALL_REAL, and UNIT_ROUNDOFF
  55. *------------------------------------------------------------------
  56. */
  57. #if defined(SUNDIALS_SINGLE_PRECISION)
  58. typedef float realtype;
  59. # define RCONST(x) x##F
  60. # define BIG_REAL FLT_MAX
  61. # define SMALL_REAL FLT_MIN
  62. # define UNIT_ROUNDOFF FLT_EPSILON
  63. #elif defined(SUNDIALS_DOUBLE_PRECISION)
  64. typedef double realtype;
  65. # define RCONST(x) x
  66. # define BIG_REAL DBL_MAX
  67. # define SMALL_REAL DBL_MIN
  68. # define UNIT_ROUNDOFF DBL_EPSILON
  69. #elif defined(SUNDIALS_EXTENDED_PRECISION)
  70. typedef long double realtype;
  71. # define RCONST(x) x##L
  72. # define BIG_REAL LDBL_MAX
  73. # define SMALL_REAL LDBL_MIN
  74. # define UNIT_ROUNDOFF LDBL_EPSILON
  75. #endif
  76. /*
  77. *------------------------------------------------------------------
  78. * Type : booleantype
  79. *------------------------------------------------------------------
  80. * Constants : FALSE and TRUE
  81. *------------------------------------------------------------------
  82. * ANSI C does not have a built-in boolean data type. Below is the
  83. * definition for a new type called booleantype. The advantage of
  84. * using the name booleantype (instead of int) is an increase in
  85. * code readability. It also allows the programmer to make a
  86. * distinction between int and boolean data. Variables of type
  87. * booleantype are intended to have only the two values FALSE and
  88. * TRUE which are defined below to be equal to 0 and 1,
  89. * respectively.
  90. *------------------------------------------------------------------
  91. */
  92. #ifndef booleantype
  93. #define booleantype int
  94. #endif
  95. #ifndef FALSE
  96. #define FALSE 0
  97. #endif
  98. #ifndef TRUE
  99. #define TRUE 1
  100. #endif
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif