function [dspencresult,x]=dspenc(x);
dspencresult=[];
persistent aln first firstCall nspenc pi26 spencs xbig ; if isempty(firstCall),firstCall=1;end;
;
if isempty(nspenc), nspenc=0; end;
%***BEGIN PROLOGUE DSPENC
%***PURPOSE Compute a form of Spence's integral due to K. Mitchell.
%***LIBRARY SLATEC (FNLIB)
%***CATEGORY C5
%***TYPE doubleprecision (SPENC-S, DSPENC-D)
%***KEYWORDS FNLIB, SPECIAL FUNCTIONS, SPENCE'S INTEGRAL
%***AUTHOR Fullerton, W., (LANL)
%***DESCRIPTION
%
% DSPENC(X) calculates the doubleprecision Spence's integral
% for doubleprecision argument X. Spence's function defined by
% integral from 0 to X of -LOG(1-Y)/Y DY.
% For ABS(X) .LE. 1, the uniformly convergent expansion
% DSPENC = sum K=1,infinity X**K / K**2 is valid.
% This is a form of Spence's integral due to K. Mitchell which differs
% from the definition in the NBS Handbook of Mathematical Functions.
%
% Spence's function can be used to evaluate much more general integral
% forms. For example,
% integral from 0 to Z of LOG(A*X+B)/(C*X+D) DX =
% LOG(ABS(B-A*D/C))*LOG(ABS(A*(C*X+D)/(A*D-B*C)))/C
% - DSPENC (A*(C*Z+D)/(A*D-B*C)) / C.
%
% Ref -- K. Mitchell, Philosophical Magazine, 40, p.351 (1949).
% Stegun and Abromowitz, AMS 55, p.1004.
%
%
% Series for SPEN on the interval 0. to 5.00000E-01
% with weighted error 4.74E-32
% log weighted error 31.32
% significant figures required 30.37
% decimal places required 32.11
%
%***REFERENCES (NONE)
%***ROUTINES CALLED D1MACH, DCSEVL, INITDS
%***REVISION HISTORY (YYMMDD)
% 780201 DATE WRITTEN
% 890531 Changed all specific intrinsics to generic. (WRB)
% 891115 Corrected third argument in reference to INITDS. (WRB)
% 891115 REVISION DATE from Version 3.2
% 891214 Prologue converted to Version 4.0 format. (BAB)
%***end PROLOGUE DSPENC
if isempty(spencs), spencs=zeros(1,38); end;
if isempty(aln), aln=0; end;
if isempty(pi26), pi26=0; end;
if isempty(xbig), xbig=0; end;
if isempty(first), first=false; end;
if firstCall, spencs(1)=[+.1527365598892405872946684910028d+0]; end;
if firstCall, spencs(2)=[+.8169658058051014403501838185271d-1]; end;
if firstCall, spencs(3)=[+.5814157140778730872977350641182d-2]; end;
if firstCall, spencs(4)=[+.5371619814541527542247889005319d-3]; end;
if firstCall, spencs(5)=[+.5724704675185826233210603054782d-4]; end;
if firstCall, spencs(6)=[+.6674546121649336343607835438589d-5]; end;
if firstCall, spencs(7)=[+.8276467339715676981584391689011d-6]; end;
if firstCall, spencs(8)=[+.1073315673030678951270005873354d-6]; end;
if firstCall, spencs(9)=[+.1440077294303239402334590331513d-7]; end;
if firstCall, spencs(10)=[+.1984442029965906367898877139608d-8]; end;
if firstCall, spencs(11)=[+.2794005822163638720201994821615d-9]; end;
if firstCall, spencs(12)=[+.4003991310883311823072580445908d-10]; end;
if firstCall, spencs(13)=[+.5823462892044638471368135835757d-11]; end;
if firstCall, spencs(14)=[+.8576708692638689278097914771224d-12]; end;
if firstCall, spencs(15)=[+.1276862586280193045989483033433d-12]; end;
if firstCall, spencs(16)=[+.1918826209042517081162380416062d-13]; end;
if firstCall, spencs(17)=[+.2907319206977138177795799719673d-14]; end;
if firstCall, spencs(18)=[+.4437112685276780462557473641745d-15]; end;
if firstCall, spencs(19)=[+.6815727787414599527867359135607d-16]; end;
if firstCall, spencs(20)=[+.1053017386015574429547019416644d-16]; end;
if firstCall, spencs(21)=[+.1635389806752377100051821734570d-17]; end;
if firstCall, spencs(22)=[+.2551852874940463932310901642581d-18]; end;
if firstCall, spencs(23)=[+.3999020621999360112770470379519d-19]; end;
if firstCall, spencs(24)=[+.6291501645216811876514149171199d-20]; end;
if firstCall, spencs(25)=[+.9933827435675677643803887752533d-21]; end;
if firstCall, spencs(26)=[+.1573679570749964816721763805866d-21]; end;
if firstCall, spencs(27)=[+.2500595316849476129369270954666d-22]; end;
if firstCall, spencs(28)=[+.3984740918383811139210663253333d-23]; end;
if firstCall, spencs(29)=[+.6366473210082843892691326293333d-24]; end;
if firstCall, spencs(30)=[+.1019674287239678367077061973333d-24]; end;
if firstCall, spencs(31)=[+.1636881058913518841111074133333d-25]; end;
if firstCall, spencs(32)=[+.2633310439417650117345279999999d-26]; end;
if firstCall, spencs(33)=[+.4244811560123976817224362666666d-27]; end;
if firstCall, spencs(34)=[+.6855411983680052916824746666666d-28]; end;
if firstCall, spencs(35)=[+.1109122433438056434018986666666d-28]; end;
if firstCall, spencs(36)=[+.1797431304999891457365333333333d-29]; end;
if firstCall, spencs(37)=[+.2917505845976095173290666666666d-30]; end;
if firstCall, spencs(38)=[+.4742646808928671061333333333333d-31]; end;
if firstCall, pi26=[+1.644934066848226436472415166646025189219d0]; end;
if firstCall, first=[true]; end;
firstCall=0;
%***FIRST EXECUTABLE STATEMENT DSPENC
if( first )
[nspenc ,spencs]=initds(spencs,38,0.1.*real(d1mach(3)));
xbig = 1.0d0./d1mach(3);
end;
first = false;
%
if( x>2.0d0 )
%
% X .GT. 2.0
%
dspencresult = 2.0d0.*pi26 - 0.5d0.*log(x).^2;
if( x<xbig )
dspencresult = dspencresult -(1.0d0+dcsevl(4.0d0./x-1.0d0,spencs,nspenc))./x;
end;
elseif( x>1.0d0 ) ;
%
% 1.0 .LT. X .LE. 2.0
%
dspencresult = pi26 - 0.5d0.*log(x).*log((x-1.0d0).^2./x) +(x-1.0d0).*(1.0d0+dcsevl(4.0d0.*(x-1.0d0)./x-1.0d0,spencs,nspenc))./x;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
return;
elseif( x>0.5d0 ) ;
%
% 0.5 .LT. X .LE. 1.0
%
dspencresult = pi26;
if( x~=1.0d0 )
dspencresult = pi26 - log(x).*log(1.0d0-x) -(1.0d0-x).*(1.0d0+dcsevl(4.0d0.*(1.0d0-x)-1.0d0,spencs,nspenc));
end;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
return;
elseif( x>=0.0d0 ) ;
%
% 0.0 .LE. X .LE. 0.5
%
dspencresult = x.*(1.0d0+dcsevl(4.0d0.*x-1.0d0,spencs,nspenc));
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
return;
elseif( x>(-1.0d0) ) ;
%
% -1.0 .LT. X .LT. 0.0
%
dspencresult = -0.5d0.*log(1.0d0-x).^2 - x.*(1.0d0+dcsevl(4.0d0.*x./(x-1.0d0)-1.0d0,spencs,nspenc))./(x-1.0d0);
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
return;
else;
%
% HERE IF X .LE. -1.0
%
aln = log(1.0d0-x);
dspencresult = -pi26 - 0.5d0.*aln.*(2.0d0.*log(-x)-aln);
if( x>(-xbig) )
dspencresult = dspencresult +(1.0d0+dcsevl(4.0d0./(1.0d0-x)-1.0d0,spencs,nspenc))./(1.0d0-x);
end;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
return;
end;
%
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
end
%DECK DSPFA