/* * (C) Copyright 2005- ECMWF. * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. * * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ #pragma once /* Return n to the power of s */ template constexpr T codes_power(long s, long n) { T divisor = 1.0; if (s == 0) return 1.0; if (s == 1) return n; while (s < 0) { divisor /= n; s++; } while (s > 0) { divisor *= n; s--; } return divisor; }