1 /* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_MATH_UTILS_H_
7 #define SIMGRID_MATH_UTILS_H_
9 #include <xbt/asserts.h>
10 #include <xbt/function_types.h>
15 static inline void double_update(double* variable, double value, double precision)
18 fprintf(stderr, "Updating %g -= %g +- %g\n", *variable, value, precision);
19 xbt_assert(value == 0.0 || value > precision);
20 // Check that precision is higher than the machine-dependent size of the mantissa. If not, brutal rounding may
21 // happen, and the precision mechanism is not active...
22 xbt_assert(FLT_RADIX == 2 && *variable < precision * exp2(DBL_MANT_DIG));
25 if (*variable < precision)
29 static inline int double_positive(double value, double precision)
31 return (value > precision);
34 static inline int double_equals(double value1, double value2, double precision)
36 return (fabs(value1 - value2) < precision);
39 #endif /* SIMGRID_MATH_UTILS_H_ */