'use strict';

/*
* The original C code, long comment, copyright, license, and constants are from [Cephes]{@link http://www.netlib.org/cephes/}.
*
* The implementation follows the original, but has been modified for JavaScript.
*/

/*
* COPYRIGHT
*
* Cephes Math Library Release 2.1:  January, 1989
* Copyright 1985, 1987, 1989 by Stephen L. Moshier
*
*
* LICENSE
*
* The README [file]{@link http://netlib.sandia.gov/cephes/} reads:
*   > Some software in this archive may be from the book _Methods and Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) or from the Cephes Mathematical Library, a commercial product. In either event, it is copyrighted by the author. What you see here may be used freely but it comes with no support or guarantee.
*   > The two known misprints in the book are repaired here in the source listings for the gamma function and the incomplete beta integral.
*   > Stephen L. Moshier
*   > moshier@na-net.ornl.gov
*/

// MODULES //

var evalpoly = require( '@stdlib/math/base/tools/evalpoly' ).factory;
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var ln = require( '@stdlib/math/base/special/ln' );
var PI_SQUARED = require( '@stdlib/math/constants/float64-pi-squared' );


// VARIABLES //

var A = [
	1.00000000000000000126e0,
	3.29771340985225106936e0,
	4.25697156008121755724e0,
	2.71149851196553469920e0,
	8.79691311754530315341e-1,
	1.33847639578309018650e-1,
	7.31589045238094711071e-3,
	4.65128586073990045278e-5
];
var B = [
	9.99999999999999998740e-1,
	3.54771340985225096217e0,
	5.03278880143316990390e0,
	3.63800533345137075418e0,
	1.41172597751831069617e0,
	2.82974860602568089943e-1,
	2.54043763932544379113e-2,
	6.90990488912553276999e-4
];


// FUNCTIONS //

// Compile functions to evaluate polynomials based on the above coefficients...
var polyvalA = evalpoly( A );
var polyvalB = evalpoly( B );


// MAIN //

/**
* Evaluates Spence’s function, which is also known as the dilogarithm.
*
* #### Method
*
* * A rational approximation gives the integral in the interval (0.5, 1.5).
* * Transformation formulas for \\( \tfrac{1}{x} \\) and \\( 1 - x \\) are employed outside the basic expansion range.
*
* #### Notes
*
* * Relative error:
*
*   | arithmetic | domain      | # trials | peak    | rms     |
*   |:----------:|:-----------:|:--------:|:-------:|:-------:|
*   | IEEE       | 0,4         | 30000    | 3.9e-15 | 5.4e-16 |
*
*
* @param {NonNegativeNumber} x - input value
* @returns {number} function value
*
* @example
* var v = spence( 3.0 );
* // returns ~-1.437
* @example
* var v = spence( 0.0 );
* // returns ~1.645
* @example
* var v = spence( -9.0 );
* // returns NaN
* @example
* var v = spence( NaN );
* // returns NaN
*/
function spence( x ) {
	var flg;
	var w;
	var y;
	var z;

	if ( isnan( x ) || x < 0.0 ) {
		return NaN;
	}
	if ( x === 1.0 ) {
		return 0.0;
	}
	if ( x === 0.0 ) {
		return ( PI_SQUARED / 6.0 );
	}
	flg = 0;
	if ( x > 2.0 ) {
		x = 1.0 / x;
		flg |= 2;
	}
	if ( x > 1.5 ) {
		w = (1.0 / x) - 1.0;
		flg |= 2;
	}
	else if (x < 0.5) {
		w = -x;
		flg |= 1;
	}
	else {
		w = x - 1.0;
	}
	y = -w * polyvalA( w ) / polyvalB( w );
	if ( flg & 1 ) {
		y = ( PI_SQUARED / 6.0 ) - ( ln( x ) * ln( 1.0-x ) ) - y;
	}
	if ( flg & 2 ) {
		z = ln( x );
		y = -( 0.5 * z * z ) - y;
	}
	return y;
} // end FUNCTION spence()


// EXPORTS //

module.exports = spence;

@@ -3059,15 +3059,17 @@
 if (
+ 
 x %3C 0.5
+ 
 ) %7B%0A

Add missing spaces