function [d9ln2rresult,x]=d9ln2r(x);
d9ln2rresult=[];
persistent eps first firstCall ln21cs ln22cs ntln21 ntln22 sqeps txbig txmax xbig xmax xmin ; if isempty(firstCall),firstCall=1;end;
;
if isempty(eps), eps=0; end;
if isempty(sqeps), sqeps=0; end;
if isempty(ntln21), ntln21=0; end;
if isempty(ntln22), ntln22=0; end;
%***BEGIN PROLOGUE D9LN2R
%***SUBSIDIARY
%***PURPOSE Evaluate LOG(1+X) from second order relative accuracy so
% that LOG(1+X) = X - X**2/2 + X**3*D9LN2R(X)
%***LIBRARY SLATEC (FNLIB)
%***CATEGORY C4B
%***TYPE doubleprecision (R9LN2R-S, D9LN2R-D, C9LN2R-C)
%***KEYWORDS ELEMENTARY FUNCTIONS, FNLIB, LOGARITHM, SECOND ORDER
%***AUTHOR Fullerton, W., (LANL)
%***DESCRIPTION
%
% Evaluate LOG(1+X) from 2-nd order with relative error accuracy so
% that LOG(1+X) = X - X**2/2 + X**3*D9LN2R(X)
%
% Series for LN21 on the interval -6.25000E-01 to 0.
% with weighted error 1.82E-32
% log weighted error 31.74
% significant figures required 31.00
% decimal places required 32.59
%
% Series for LN22 on the interval 0. to 8.12500E-01
% with weighted error 6.10E-32
% log weighted error 31.21
% significant figures required 30.32
% decimal places required 32.00
%
%***REFERENCES (NONE)
%***ROUTINES CALLED D1MACH, DCSEVL, INITDS, XERMSG
%***REVISION HISTORY (YYMMDD)
% 780401 DATE WRITTEN
% 890531 Changed all specific intrinsics to generic. (WRB)
% 890911 Removed unnecessary intrinsics. (WRB)
% 890911 REVISION DATE from Version 3.2
% 891214 Prologue converted to Version 4.0 format. (BAB)
% 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
% 900720 Routine changed from user-callable to subsidiary. (WRB)
%***end PROLOGUE D9LN2R
if isempty(xbig), xbig=0; end;
if isempty(txbig), txbig=0; end;
if isempty(xmax), xmax=0; end;
if isempty(txmax), txmax=0; end;
if isempty(xmin), xmin=0; end;
if isempty(ln21cs), ln21cs=zeros(1,50); end;
if isempty(ln22cs), ln22cs=zeros(1,37); end;
if isempty(first), first=false; end;
if firstCall, ln21cs(1)=[+.18111962513478809875894953043071d+0]; end;
if firstCall, ln21cs(2)=[-.15627123192872462669625155541078d+0]; end;
if firstCall, ln21cs(3)=[+.28676305361557275209540627102051d-1]; end;
if firstCall, ln21cs(4)=[-.55586996559481398781157725126781d-2]; end;
if firstCall, ln21cs(5)=[+.11178976652299837657335666279727d-2]; end;
if firstCall, ln21cs(6)=[-.23080508982327947182299279585705d-3]; end;
if firstCall, ln21cs(7)=[+.48598853341100175874681558068750d-4]; end;
if firstCall, ln21cs(8)=[-.10390127388903210765514242633338d-4]; end;
if firstCall, ln21cs(9)=[+.22484563707390128494621804946408d-5]; end;
if firstCall, ln21cs(10)=[-.49140592739266484875327802597091d-6]; end;
if firstCall, ln21cs(11)=[+.10828256507077483336620152971597d-6]; end;
if firstCall, ln21cs(12)=[-.24025872763420701435976675416719d-7]; end;
if firstCall, ln21cs(13)=[+.53624600472708133762984443250163d-8]; end;
if firstCall, ln21cs(14)=[-.12029951362138772264671646424377d-8]; end;
if firstCall, ln21cs(15)=[+.27107889277591860785622551632266d-9]; end;
if firstCall, ln21cs(16)=[-.61323562618319010068796728430690d-10]; end;
if firstCall, ln21cs(17)=[+.13920858369159469857436908543978d-10]; end;
if firstCall, ln21cs(18)=[-.31699300330223494015283057260883d-11]; end;
if firstCall, ln21cs(19)=[+.72383754044307505335214326197011d-12]; end;
if firstCall, ln21cs(20)=[-.16570017184764411391498805506268d-12]; end;
if firstCall, ln21cs(21)=[+.38018428663117424257364422631876d-13]; end;
if firstCall, ln21cs(22)=[-.87411189296972700259724429899137d-14]; end;
if firstCall, ln21cs(23)=[+.20135619845055748302118751028154d-14]; end;
if firstCall, ln21cs(24)=[-.46464456409033907031102008154477d-15]; end;
if firstCall, ln21cs(25)=[+.10739282147018339453453338554925d-15]; end;
if firstCall, ln21cs(26)=[-.24858534619937794755534021833960d-16]; end;
if firstCall, ln21cs(27)=[+.57620197950800189813888142628181d-17]; end;
if firstCall, ln21cs(28)=[-.13373063769804394701402199958050d-17]; end;
if firstCall, ln21cs(29)=[+.31074653227331824966533807166805d-18]; end;
if firstCall, ln21cs(30)=[-.72288104083040539906901957917627d-19]; end;
if firstCall, ln21cs(31)=[+.16833783788037385103313258186888d-19]; end;
if firstCall, ln21cs(32)=[-.39239463312069958052519372739925d-20]; end;
if firstCall, ln21cs(33)=[+.91551468387536789746385528640853d-21]; end;
if firstCall, ln21cs(34)=[-.21378895321320159520982095801002d-21]; end;
if firstCall, ln21cs(35)=[+.49964507479047864699828564568746d-22]; end;
if firstCall, ln21cs(36)=[-.11686240636080170135360806147413d-22]; end;
if firstCall, ln21cs(37)=[+.27353123470391863775628686786559d-23]; end;
if firstCall, ln21cs(38)=[-.64068025084792111965050345881599d-24]; end;
if firstCall, ln21cs(39)=[+.15016293204334124162949071940266d-24]; end;
if firstCall, ln21cs(40)=[-.35217372410398479759497145002666d-25]; end;
if firstCall, ln21cs(41)=[+.82643901014814767012482733397333d-26]; end;
if firstCall, ln21cs(42)=[-.19404930275943401918036617898666d-26]; end;
if firstCall, ln21cs(43)=[+.45587880018841283562451588437333d-27]; end;
if firstCall, ln21cs(44)=[-.10715492087545202154378625023999d-27]; end;
if firstCall, ln21cs(45)=[+.25199408007927592978096674133333d-28]; end;
if firstCall, ln21cs(46)=[-.59289088400120969341750476800000d-29]; end;
if firstCall, ln21cs(47)=[+.13955864061057513058237153279999d-29]; end;
if firstCall, ln21cs(48)=[-.32864578813478583431436697599999d-30]; end;
if firstCall, ln21cs(49)=[+.77424967950478166247254698666666d-31]; end;
if firstCall, ln21cs(50)=[-.18247735667260887638125226666666d-31]; end;
if firstCall, ln22cs(1)=[-.2224253253502046082986015223552d+0]; end;
if firstCall, ln22cs(2)=[-.6104710010807862398680104755764d-1]; end;
if firstCall, ln22cs(3)=[+.7427235009750394590519629755729d-2]; end;
if firstCall, ln22cs(4)=[-.9335018261636970565612779606397d-3]; end;
if firstCall, ln22cs(5)=[+.1200499076872601283350731287359d-3]; end;
if firstCall, ln22cs(6)=[-.1570472295282004112823352608243d-4]; end;
if firstCall, ln22cs(7)=[+.2081874781051271096050783592759d-5]; end;
if firstCall, ln22cs(8)=[-.2789195577646713654057213051375d-6]; end;
if firstCall, ln22cs(9)=[+.3769355823760132058422895135447d-7]; end;
if firstCall, ln22cs(10)=[-.5130902896527711258240589938003d-8]; end;
if firstCall, ln22cs(11)=[+.7027141178150694738206218215392d-9]; end;
if firstCall, ln22cs(12)=[-.9674859550134342389243972005137d-10]; end;
if firstCall, ln22cs(13)=[+.1338104645924887306588496449748d-10]; end;
if firstCall, ln22cs(14)=[-.1858102603534063981628453846591d-11]; end;
if firstCall, ln22cs(15)=[+.2589294422527919749308600123070d-12]; end;
if firstCall, ln22cs(16)=[-.3619568316141588674466025382172d-13]; end;
if firstCall, ln22cs(17)=[+.5074037398016623088006858917396d-14]; end;
if firstCall, ln22cs(18)=[-.7131012977031127302700938748927d-15]; end;
if firstCall, ln22cs(19)=[+.1004490328554567481853386784126d-15]; end;
if firstCall, ln22cs(20)=[-.1417906532184025791904405075285d-16]; end;
if firstCall, ln22cs(21)=[+.2005297034743326117891086396074d-17]; end;
if firstCall, ln22cs(22)=[-.2840996662339803305365396717567d-18]; end;
if firstCall, ln22cs(23)=[+.4031469883969079899599878662826d-19]; end;
if firstCall, ln22cs(24)=[-.5729325241832207320455498956799d-20]; end;
if firstCall, ln22cs(25)=[+.8153488253890010675848928733866d-21]; end;
if firstCall, ln22cs(26)=[-.1161825588549721787606027468799d-21]; end;
if firstCall, ln22cs(27)=[+.1657516611662538343659339775999d-22]; end;
if firstCall, ln22cs(28)=[-.2367336704710805190114017280000d-23]; end;
if firstCall, ln22cs(29)=[+.3384670367975521386076569599999d-24]; end;
if firstCall, ln22cs(30)=[-.4843940829215718204296396799999d-25]; end;
if firstCall, ln22cs(31)=[+.6938759162514273718676138666666d-26]; end;
if firstCall, ln22cs(32)=[-.9948142607031436571923797333333d-27]; end;
if firstCall, ln22cs(33)=[+.1427440611211698610634752000000d-27]; end;
if firstCall, ln22cs(34)=[-.2049794721898234911566506666666d-28]; end;
if firstCall, ln22cs(35)=[+.2945648756401362222885546666666d-29]; end;
if firstCall, ln22cs(36)=[-.4235973185184957027669333333333d-30]; end;
if firstCall, ln22cs(37)=[+.6095532614003832040106666666666d-31]; end;
if firstCall, first=[true]; end;
firstCall=0;
%***FIRST EXECUTABLE STATEMENT D9LN2R
if( first )
[eps ]=d1mach(3);
[ntln21 ,ln21cs]=initds(ln21cs,50,0.1.*eps);
[ntln22 ,ln22cs]=initds(ln22cs,37,0.1.*eps);
%
xmin = -1.0d0 + sqrt(d1mach(4));
sqeps = sqrt(eps);
txmax = 8.0./sqeps;
xmax = txmax -(eps.*txmax.^2-2.0d0.*log(txmax))./(2.0d0.*eps.*txmax);
txbig = 6.0./sqrt(sqeps);
xbig = txbig -(sqeps.*txbig.^2-2.0d0.*log(txbig))./(2.0d0.*sqeps.*txbig);
end;
first = false;
%
if( x<(-.625d0) || x>0.8125d0 )
%
if( x<xmin )
xermsg('SLATEC','D9LN2R','ANSWER LT HALF PRECISION BECAUSE X IS TOO NEAR -1',1,1);
end;
if( x>xmax )
xermsg('SLATEC','D9LN2R','NO PRECISION IN ANSWER BECAUSE X IS TOO BIG',3,2);
end;
if( x>xbig )
xermsg('SLATEC','D9LN2R','ANSWER LT HALF PRECISION BECAUSE X IS TOO BIG',2,1);
end;
%
d9ln2rresult =(log(1.0d0+x)-x.*(1.0d0-0.5d0.*x))./x.^3;
else;
%
if( x<0.0d0 )
d9ln2rresult = 0.375d0 +dcsevl(16.0d0.*x./5.0d0+1.0d0,ln21cs,ntln21);
end;
if( x>=0.0d0 )
d9ln2rresult = 0.375d0 + dcsevl(32.0d0.*x./13.0d0-1.0d0,ln22cs,ntln22);
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 D9PAK