Make last-split a bit faster
authorMartin C. Frith
Mon Mar 16 11:42:45 2020 +0900 (2 months ago)
changeset 1059a380494ff77b
parent 1058 0b3571f8e14b
child 1060 ca3f417edc01
Make last-split a bit faster
src/split/cbrc_int_exponentiator.hh
     1.1 --- a/src/split/cbrc_int_exponentiator.hh	Mon Mar 16 11:25:17 2020 +0900
     1.2 +++ b/src/split/cbrc_int_exponentiator.hh	Mon Mar 16 11:42:45 2020 +0900
     1.3 @@ -17,9 +17,23 @@
     1.4    void setBase(double b) {
     1.5      base = b;
     1.6      invBase = 1.0 / b;
     1.7 +
     1.8 +    double y = 1;
     1.9 +    double z = 1;
    1.10 +    for (int i = 0; i < 128; ++i) {
    1.11 +      lookup[128 + i] = y;
    1.12 +      y *= base;
    1.13 +      z *= invBase;
    1.14 +      lookup[127 - i] = z;
    1.15 +    }
    1.16    }
    1.17  
    1.18    double operator()(int exponent) const {
    1.19 +    unsigned u = exponent + 128;
    1.20 +    if (u < 256) {
    1.21 +      return lookup[u];
    1.22 +    }
    1.23 +
    1.24      unsigned n = exponent;
    1.25      double x;
    1.26      if (exponent >= 0) {
    1.27 @@ -40,6 +54,7 @@
    1.28  private:
    1.29    double base;
    1.30    double invBase;
    1.31 +  double lookup[256];
    1.32  };
    1.33  
    1.34  }