/[svn]/linuxsampler/trunk/src/common/RTMath.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/RTMath.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3574 by schoenebeck, Thu Dec 15 12:47:45 2016 UTC revision 3575 by schoenebeck, Wed Aug 28 11:12:04 2019 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2016 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2019 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 107  RTMathBase::usecs_t RTMathBase::unsafeMi Line 107  RTMathBase::usecs_t RTMathBase::unsafeMi
107      #endif      #endif
108  }  }
109    
110    bool RTMathBase::fEqual32(float a, float b) {
111        if (isinf(a) || isinf(b))
112            return isinf(a) == isinf(b);
113        if (isnan(a) || isnan(b))
114            return isnan(a) == isnan(b);
115    
116        const int bits = 23 /* float32 type fraction bits */ - 4 /* arbitrarily reduced bit tolerance */;
117    
118        if (a == 0.f)
119            return fabs(b) < (1.0 / pow(2, bits));
120        if (b == 0.f)
121            return fabs(a) < (1.0 / pow(2, bits));
122    
123        const double epsilon = fabs(a / pow(2.0, bits));
124        return fabs(b - a) <= epsilon;
125    }
126    
127    bool RTMathBase::fEqual64(double a, double b) {
128        if (isinf(a) || isinf(b))
129            return isinf(a) == isinf(b);
130        if (isnan(a) || isnan(b))
131            return isnan(a) == isnan(b);
132    
133        const int bits = 52 /* float64 type fraction bits */ - 4 /* arbitrarily reduced bit tolerance */;
134    
135        if (a == 0.f)
136            return fabs(b) < (1.0 / pow(2, bits));
137        if (b == 0.f)
138            return fabs(a) < (1.0 / pow(2, bits));
139    
140        const double epsilon = fabs(a / pow(2.0, bits));
141        return fabs(b - a) <= epsilon;
142    }
143    
144  /**  /**
145   * Will automatically be called once to initialize the 'Cents to frequency   * Will automatically be called once to initialize the 'Cents to frequency
146   * ratio' table.   * ratio' table.

Legend:
Removed from v.3574  
changed lines
  Added in v.3575

  ViewVC Help
Powered by ViewVC