function value = r8_bide ( x )

%*****************************************************************************80
%
%% R8_BIDE: exponentially scaled derivative, Airy function Bi of an R8 argument.
%
%  Discussion:
%
%    if X < 0,
%      R8_BIDE ( X ) = R8_BID ( X )
%    else
%      R8_BIDE ( X ) = R8_BID ( X ) * exp ( - 2/3 * X**(3/2) )
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    20 October 2011
%
%  Author:
%
%    Original FORTRAN77 version by Wayne Fullerton.
%    MATLAB version by John Burkardt.
%
%  Reference:
%
%    Wayne Fullerton,
%    Portable Special Function Routines,
%    in Portability of Numerical Software,
%    edited by Wayne Cowell,
%    Lecture Notes in Computer Science, Volume 57,
%    Springer 1977,
%    ISBN: 978-3-540-08446-4,
%    LC: QA297.W65.
%
%  Parameters:
%
%    Input, real X, the argument.
%
%    Output, real VALUE, the exponentially scaled derivative of
%    the Airy function Bi of X.
%
  persistent atr
  persistent bif2cs
  persistent bifcs
  persistent big2cs
  persistent bigcs
  persistent bip1cs
  persistent bip2cs
  persistent btr
  persistent nbif
  persistent nbif2
  persistent nbig
  persistent nbig2
  persistent nbip1
  persistent nbip2
  persistent x2sml
  persistent x3sml
  persistent x32sml
  persistent xbig

  atr = 8.75069057084843450880771988210148;
  btr = -2.09383632135605431360096498526268;

  if ( isempty ( nbif ) )

    bif2cs = [ ...
       0.32349398760352203352119193596266015, ...
       0.08629787153556355913888835323811100, ...
       0.00299402555265539742613821050727155, ...
       0.00005143052836466163720464316950821, ...
       0.00000052584025003681146026033098613, ...
       0.00000000356175137395770028102730600, ...
       0.00000000001714686400714584830518308, ...
       0.00000000000006166351969232555406693, ...
       0.00000000000000017191082154315985806, ...
       0.00000000000000000038236889518803943, ...
       0.00000000000000000000069424173624884, ...
       0.00000000000000000000000104833932510, ...
       0.00000000000000000000000000133721972, ...
       0.00000000000000000000000000000145986, ...
       0.00000000000000000000000000000000138 ]';
    bifcs = [ ...
       0.115353679082857024267474446284908879, ...
       0.020500789404919287530357789445940252, ...
       0.000213529027890287581892679619451158, ...
       0.000001078396061467683042209155523569, ...
       0.000000003209470883320666783353670420, ...
       0.000000000006293040671833540390213316, ...
       0.000000000000008740304300063083340121, ...
       0.000000000000000009047915683496049529, ...
       0.000000000000000000007249923164709251, ...
       0.000000000000000000000004629576649604, ...
       0.000000000000000000000000002411236436, ...
       0.000000000000000000000000000001043825, ...
       0.000000000000000000000000000000000382 ]';
    big2cs = [ ...
       1.606299946362129457759284537862622883, ...
       0.744908881987608865201476685194753972, ...
       0.047013873861027737964095177635353019, ...
       0.001228442206254823907016188785848091, ...
       0.000017322241225662362670987355613727, ...
       0.000000152190165236801893711508366563, ...
       0.000000000911356024911957704145528786, ...
       0.000000000003954791842356644201722554, ...
       0.000000000000013001737033862320007309, ...
       0.000000000000000033493506858269079763, ...
       0.000000000000000000069419094403694057, ...
       0.000000000000000000000118248256604581, ...
       0.000000000000000000000000168462493472, ...
       0.000000000000000000000000000203684674, ...
       0.000000000000000000000000000000211619, ...
       0.000000000000000000000000000000000191 ]';
    bigcs = [ ...
      -0.0971964404164435373897790974606802, ...
       0.1495035768431670665710843445326264, ...
       0.0031135253871213260419419176839631, ...
       0.0000247085705798212967777021920569, ...
       0.0000001029496277313786081987324295, ...
       0.0000000002639703739869432892676778, ...
       0.0000000000004582792707803206608181, ...
       0.0000000000000005742829740893447321, ...
       0.0000000000000000005438275385238549, ...
       0.0000000000000000000004028347267083, ...
       0.0000000000000000000000002397823826, ...
       0.0000000000000000000000000001171956, ...
       0.0000000000000000000000000000000479 ]';
    bip1cs = [ ...
      -0.17291873510795537186124679823741003, ...
      -0.01493584929846943639486231021818675, ...
      -0.00054711049516785663990658697874460, ...
       0.00015379662929584083449573727856666, ...
       0.00001543534761921794131028948022869, ...
      -0.00000654341138519060129226087106765, ...
       0.00000037280824078787032232152275240, ...
       0.00000020720783881887480080810710514, ...
      -0.00000006581733364696191689495883922, ...
       0.00000000749267463539288212986048985, ...
       0.00000000111013368840707147698890101, ...
      -0.00000000072651405529159512323880794, ...
       0.00000000017827235598470153962165668, ...
      -0.00000000002173463524809506269656807, ...
      -0.00000000000203020349653882594017049, ...
       0.00000000000193118272294077519319859, ...
      -0.00000000000060449525048290296023117, ...
       0.00000000000012094496248933664277802, ...
      -0.00000000000001251088360074479784619, ...
      -0.00000000000000199173832424881344036, ...
       0.00000000000000151540816342864303038, ...
      -0.00000000000000049768927059816240250, ...
       0.00000000000000011545959731810501403, ...
      -0.00000000000000001863286862907983871, ...
       0.00000000000000000099330392344759104, ...
       0.00000000000000000068182083667412417, ...
      -0.00000000000000000034854456479650551, ...
       0.00000000000000000010860382134235961, ...
      -0.00000000000000000002599290185240166, ...
       0.00000000000000000000476895370459000, ...
      -0.00000000000000000000051946940777177, ...
      -0.00000000000000000000005925575044912, ...
       0.00000000000000000000005746008970972, ...
      -0.00000000000000000000002186119806494, ...
       0.00000000000000000000000624124294738, ...
      -0.00000000000000000000000146003421785, ...
       0.00000000000000000000000027493893904, ...
      -0.00000000000000000000000003474678018, ...
      -0.00000000000000000000000000109303694, ...
       0.00000000000000000000000000261972744, ...
      -0.00000000000000000000000000112365018, ...
       0.00000000000000000000000000035152059, ...
      -0.00000000000000000000000000009167601, ...
       0.00000000000000000000000000002040203, ...
      -0.00000000000000000000000000000373038, ...
       0.00000000000000000000000000000046070, ...
       0.00000000000000000000000000000001748 ]';
    bip2cs = [ ...
      -0.13269705443526630494937031210217135, ...
      -0.00568443626045977481306046339037428, ...
      -0.00015643601119611609623698471216660, ...
      -0.00001136737203679562267336053207940, ...
      -0.00000143464350991283669643136951338, ...
      -0.00000018098531185164131868746481700, ...
       0.00000000926177343610865546229511422, ...
       0.00000001710005490720592181887296162, ...
       0.00000000476698163503781708252686849, ...
      -0.00000000035195022023163141945397159, ...
      -0.00000000058890614315886871574147635, ...
      -0.00000000006678499607795537597612089, ...
       0.00000000006395565101720391190697713, ...
       0.00000000001554529427064394106403245, ...
      -0.00000000000792396999744612971684001, ...
      -0.00000000000258326242689717798947525, ...
       0.00000000000121655047787849117978773, ...
       0.00000000000038707207172899985942258, ...
      -0.00000000000022487045479618229130656, ...
      -0.00000000000004953476515684046293493, ...
       0.00000000000004563781601526912756017, ...
       0.00000000000000332998314345014118494, ...
      -0.00000000000000921750185832874202719, ...
       0.00000000000000094156670658958205765, ...
       0.00000000000000167153952640716157721, ...
      -0.00000000000000055134268782182410852, ...
      -0.00000000000000022368651572006617795, ...
       0.00000000000000017486948976520089209, ...
       0.00000000000000000206518666352329750, ...
      -0.00000000000000003973060018130712479, ...
       0.00000000000000001154836935724892335, ...
       0.00000000000000000553906053678276421, ...
      -0.00000000000000000457174427396478267, ...
       0.00000000000000000026567111858284432, ...
       0.00000000000000000101599148154167823, ...
      -0.00000000000000000044821231272196246, ...
      -0.00000000000000000007959149661617295, ...
       0.00000000000000000014583615616165794, ...
      -0.00000000000000000004015127893061405, ...
      -0.00000000000000000002079152963743616, ...
       0.00000000000000000001972630449634388, ...
      -0.00000000000000000000336033404001683, ...
      -0.00000000000000000000376504832685507, ...
       0.00000000000000000000269935508825595, ...
      -0.00000000000000000000026985946069808, ...
      -0.00000000000000000000061794011788222, ...
       0.00000000000000000000038782693311711, ...
      -0.00000000000000000000002420094005071, ...
      -0.00000000000000000000009844051058925, ...
       0.00000000000000000000005954353358494, ...
      -0.00000000000000000000000361274446366, ...
      -0.00000000000000000000001552634578088, ...
       0.00000000000000000000000977819380304, ...
      -0.00000000000000000000000092239447509, ...
      -0.00000000000000000000000241545903934, ...
       0.00000000000000000000000169558652255, ...
      -0.00000000000000000000000026762408641, ...
      -0.00000000000000000000000036188116265, ...
       0.00000000000000000000000030372404951, ...
      -0.00000000000000000000000007422876903, ...
      -0.00000000000000000000000004930678544, ...
       0.00000000000000000000000005468790028, ...
      -0.00000000000000000000000001920315188, ...
      -0.00000000000000000000000000516335154, ...
       0.00000000000000000000000000957723167, ...
      -0.00000000000000000000000000463659079, ...
      -0.00000000000000000000000000004509226, ...
       0.00000000000000000000000000155617519, ...
      -0.00000000000000000000000000104156509, ...
       0.00000000000000000000000000019565323, ...
       0.00000000000000000000000000021335380, ...
      -0.00000000000000000000000000021461958, ...
       0.00000000000000000000000000007875791, ...
       0.00000000000000000000000000001713768, ...
      -0.00000000000000000000000000003917137, ...
       0.00000000000000000000000000002233559, ...
      -0.00000000000000000000000000000269383, ...
      -0.00000000000000000000000000000577764, ...
       0.00000000000000000000000000000519650, ...
      -0.00000000000000000000000000000183361, ...
      -0.00000000000000000000000000000045763, ...
       0.00000000000000000000000000000099235, ...
      -0.00000000000000000000000000000058938, ...
       0.00000000000000000000000000000009568, ...
       0.00000000000000000000000000000013758, ...
      -0.00000000000000000000000000000014066, ...
       0.00000000000000000000000000000005964, ...
       0.00000000000000000000000000000000437 ]';

    eta = 0.1 * r8_mach ( 3 );
    nbif = r8_inits ( bifcs, 13, eta );
    nbig = r8_inits ( bigcs, 13, eta );
    nbif2 = r8_inits ( bif2cs, 15, eta );
    nbig2 = r8_inits ( big2cs, 16, eta );
    nbip1 = r8_inits ( bip1cs, 47, eta );
    nbip2 = r8_inits ( bip2cs, 88, eta );
    x2sml = sqrt ( eta );
    x3sml = eta^0.3333;
    x32sml = 1.3104 * x3sml * x3sml;
    xbig = r8_mach ( 2 )^0.6666;

  end

  if ( x < -1.0 )
    [ xn, phi ] = r8_admp ( x );
    value = xn * sin ( phi );
  elseif ( abs ( x ) <= x2sml )
    x2 = 0.0;
    x3 = 0.0;
    value = x2 * ( r8_csevl ( x3, bifcs, nbif ) ...
      + 0.25 ) + r8_csevl ( x3, bigcs, nbig ) + 0.5;
    if ( x32sml < x )
      value = value * exp ( - 2.0 * x * sqrt ( x ) / 3.0 );
    end
  elseif ( abs ( x ) <= x3sml )
    x2 = x * x;
    x3 = 0.0;
    value = x2 * ( r8_csevl ( x3, bifcs, nbif ) ...
      + 0.25 ) + r8_csevl ( x3, bigcs, nbig ) + 0.5;
    if ( x32sml < x )
      value = value * exp ( - 2.0 * x * sqrt ( x ) / 3.0 );
    end
  elseif ( x <= 1.0 )
    x2 = x * x;
    x3 = x * x * x;
    value = x2 * ( r8_csevl ( x3, bifcs, nbif ) ...
      + 0.25 ) + r8_csevl ( x3, bigcs, nbig ) + 0.5;
    if ( x32sml < x )
      value = value * exp ( - 2.0 * x * sqrt ( x ) / 3.0 );
    end
  elseif ( x <= 2.0 )
    z = ( 2.0 * x * x * x - 9.0 ) / 7.0;
    value = exp ( - 2.0 * x * sqrt ( x ) / 3.0 ) ...
      * ( x * x * ( 0.25 + r8_csevl ( z, bif2cs, nbif2 ) ) ...
      + 0.5 + r8_csevl ( z, big2cs, nbig2 ) );
  elseif ( x <= 4.0 )
    sqrtx = sqrt ( x );
    z = atr / x / sqrtx + btr;
    value = ( 0.625 + r8_csevl ( z, bip1cs, nbip1 ) ) * sqrt ( sqrtx );
  elseif ( x <= xbig )
    sqrtx = sqrt ( x );
    z = 16.0 / x / sqrtx - 1.0;
    value = ( 0.625 + r8_csevl ( z, bip2cs, nbip2 ) ) * sqrt ( sqrtx );
  else
    sqrtx = sqrt ( x );
    z = -1.0;
    value = ( 0.625 + r8_csevl ( z, bip2cs, nbip2 ) ) * sqrt ( sqrtx );
  end

  return
end
