time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

odd_positive_integers.js (1675B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 *
     18 *
     19 * ## Notice
     20 *
     21 * The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_60_0/boost/math/special_functions/zeta.hpp}. The implementation follows the original, but has been modified for JavaScript.
     22 *
     23 * ```text
     24 * (C) Copyright John Maddock 2006.
     25 *
     26 * Use, modification and distribution are subject to the
     27 * Boost Software License, Version 1.0. (See accompanying file
     28 * LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
     29 * ```
     30 */
     31 
     32 'use strict';
     33 
     34 // MODULES //
     35 
     36 var series = require( './polynomial_series.js' );
     37 var ODD_POSITIVE_INTEGERS = require( './odd_positive_integers.json' );
     38 
     39 
     40 // MAIN //
     41 
     42 /**
     43 * Evaluates the Riemann zeta function for an odd positive integer.
     44 *
     45 * @private
     46 * @param {number} s - input value
     47 * @returns {number} function value
     48 *
     49 * @example
     50 * var v = zeta( 3.0 );
     51 * // returns ~1.202
     52 */
     53 function zeta( s ) {
     54 	var idx = (s-3) / 2;
     55 	if ( idx >= ODD_POSITIVE_INTEGERS.length ) {
     56 		return series( s );
     57 	}
     58 	return ODD_POSITIVE_INTEGERS[ idx ];
     59 }
     60 
     61 
     62 // EXPORTS //
     63 
     64 module.exports = zeta;