Changeset 2867


Ignore:
Timestamp:
Nov 12, 2012, 1:40:23 AM (9 years ago)
Author:
Peter
Message:

A log2 function similar to std::log10.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility.cc

    r2857 r2867  
    196196
    197197  test_compose_functors(suite);
     198
     199  double x = 8.0;
     200  suite.add(suite.equal(utility::log2(x), 3.0));
     201  float xf = x;
     202  suite.add(suite.equal(utility::log2(xf), 3.0));
     203  long double xld = 8.0;
     204  suite.add(suite.equal(utility::log2(xld), 3.0));
    198205
    199206  return suite.return_value();
  • trunk/yat/utility/utility.h

    r2820 r2867  
    11#ifndef _theplu_yat_utility_utility_
    2 #define _theplu_yat_utility_utility_ 
     2#define _theplu_yat_utility_utility_
    33
    44// $Id$
     
    3535#include "Exception.h"
    3636#include "yat_assert.h"
     37
     38#include <gsl/gsl_math.h>
    3739
    3840#include <algorithm>
     
    194196  template<typename T>
    195197  void load(std::istream& is, std::vector<T>& vec, char sep='\0');
    196  
     198
     199  /**
     200     \return base-2 logarithm of x
     201
     202     \since New in yat 0.10
     203   */
     204  // c++11 provides std::log2 so perhaps we should call that one if
     205  // availalable (but a bit tricky since this is a public header)
     206  template<typename T>
     207  T log2(T x) { return std::log(x)/M_LN2; }
     208
    197209// private namespace
    198210namespace detail {
Note: See TracChangeset for help on using the changeset viewer.