File indexing completed on 2024-05-19 15:01:47
0001 /*************************************************************************** 0002 File : nsl_math.h 0003 Project : LabPlot 0004 Description : NSL math functions 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2018-2020 by Stefan Gerlach (stefan.gerlach@uni.kn) 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #ifndef NSL_MATH_H 0030 #define NSL_MATH_H 0031 0032 #include <stdbool.h> 0033 0034 #define M_PI_180 (M_PI/180.) 0035 #define M_180_PI (180./M_PI) 0036 0037 /* 0038 * more intelligent comparison of doubles, 0039 * taken from Knuth's "The art of computer programming" 0040 */ 0041 bool nsl_math_approximately_equal(double a, double b); 0042 bool nsl_math_essentially_equal(double a, double b); 0043 bool nsl_math_definitely_greater_than(double a, double b); 0044 bool nsl_math_definitely_less_than(double a, double b); 0045 bool nsl_math_approximately_equal_eps(double a, double b, double epsilon); 0046 bool nsl_math_essentially_equal_eps(double a, double b, double epsilon); 0047 bool nsl_math_definitely_greater_than_eps(double a, double b, double epsilon); 0048 bool nsl_math_definitely_less_than_eps(double a, double b, double epsilon); 0049 0050 /* returns decimal places of signed value 0051 * 0.1 -> 1, 0.06 -> 2, 23 -> -1, 100 -> -2 0052 */ 0053 int nsl_math_decimal_places(double value); 0054 0055 /* return decimal places of signed value rounded to one digit 0056 * 0.1 -> 1, 0.006 -> 2, 0.8 -> 0, 12 -> -1, 520 -> -3 0057 */ 0058 int nsl_math_rounded_decimals(double value); 0059 0060 /* nsl_math_rounded_decimals() but max 'max' 0061 */ 0062 int nsl_math_rounded_decimals_max(double value, int max); 0063 0064 /* round double value to n decimal places */ 0065 double nsl_math_round_places(double value, unsigned int n); 0066 0067 /* round double value to precision p */ 0068 double nsl_math_round_precision(double value, unsigned int p); 0069 0070 #endif /* NSL_MATH_H */