
function CaptionR() {
  //     JAVASCRIPT INCLUDE FILE - (c) J R Stockton  >= 2009-09-26
  //             http://www.merlyn.demon.co.uk/rndg-inc.js
  //            Common functions specific to Rounding tests
  //       Routines may be copied, but URL must not be linked to.
  }

var RincT=0


// Mini-Forms to test converters :-


var FDS = 0 // Global ; controls use of TryRnd() by TestF()


function SetRndCases() { // Function defines RndCases as Global
  RndCases = [ // Actual test case numbers for this page :-
    0.0, 0.003, 0.007, 0.07, 0.70,
    0.77499, 0.77501, 3.965, 3.995, 7, 777, 999.995, 7.3e25,
    NaN, Infinity, null, undefined, 2.22222e20 ] }


SetRndCases()


function SubRnd(Fn, Sgn) { var J, St, Sg = +Sgn, T
  St = '\n&bull; ' + Sgn.charAt(0) + 'Case[] : '
  for (J = 0 ; J < RndCases.length ; J++) { T = RndCases[J]
    if (T != undefined && T != null) T *= Sg
    if (J%6==5) St += '\n&nbsp; '
    St += '"' +  Fn(T, 2, 2)  + '" ' }
  return St }


function TryRnd(Fn) { var K, St
  St = "(RndCases[], 2, 2) :" + SubRnd(Fn, "+1") + SubRnd(Fn, "-1") +
    "\nSteps of 0.005 from 12.290 to 12.410 :\n"
  for (K = 12290 ; K <= 12410 ; K += 5) {
    if (K%50==0) St += "\n"
    St += Fn(K/1000, 2, 2) + " " }
  St += "\nBankers' ? : "
  for (K = -875 ; K <= 875 ; K += 250) St += Fn(K/1000, 2, 2) + " "
  return St }


function cfToF(Func) { var J = X = 0, Tmp, S1, S2, S3
  var A = ["Compares <tt>toFixed<\/tt> and " +
      NameFunc(Func).fixed() + "<pre><small>"]
  A.push(" E \t\t\tX\t\t      toF\t\t\t    Func  Match Diff  ")
  while (X < 1E22) { X = 0.0007 * Math.pow(-3, J)
    S1 = SpcsTo(X, 25)
    Tmp = X.toFixed(2)
    if (X>0) Tmp = "+" + Tmp ; S2 = SpcsTo(Tmp, 26)
    Tmp = Func(X, 2, 2) + ""
    if (X>0) Tmp = Tmp.replace(/^(\d)/, "+$1") ; S3 = SpcsTo(Tmp, 26)
    A.push(SpcsTo(Math.log(Math.abs(X))/Math.LN10|0, 2) + "  " +
      S1 + S2 + S3 + SpcsTo(S2==S3, 7) + "   " + (S2-S3) )
    J++ }
  FreshPage("Comparisons", A.join("\n") + "<\/small><\/pre>") }


function TestF(Fn, p) { var FnN = NameFunc(Fn), S2 = '', S3 = ''
  if (FDS>0) document.writeln('<pre>', FnN, TryRnd(Fn), '<\/pre>')
  document.write('<form><pre class=TRY>',
    FnN, '( ', '<input type=text name=InA size=12> ')
  if (p>1) {
    document.write(', &nbsp;<input type=text name=InB size=2> ')
    S2 = ', +InB.value' }
  if (p>2) {
    document.write(', &nbsp;<input type=text name=InC size=2> ')
    S3 = ', +InC.value' }
  document.write(') <input type=button value="="',
    ' onClick="Ans.value='+FnN+'(InA.value'+S2+S3+')">',
    ' <input type=text name=Ans size=24 readonly>',

    '<br> <script>PopBtn(RndCases.toString()',
      '.replace(",,,", ",null,undefined,"))', 
      '.value="Cases"<\/script>', // 20090923

    ' &nbsp; <input type=button value="cf.toF" onClick="cfToF('+FnN+')">',

    '<\/pre><\/form>') }


// Old :

function OldSigFigNum(X, N) { // returns a Number
  var p = Math.pow(10, N-Math.ceil(Math.log(Math.abs(X))/Math.LN10))
  return isFinite(p) ? Math.round(X*p)/p : X }


function OldSigFigExp(X, N) { // N<22 , returns a String
  if (X==0) return OldSigFigExp(1, N).replace(/\+1/, ' 0')
  var p = Math.floor(Math.log(Math.abs(X))/Math.LN10)
  if (!isFinite(p)) return X
  return (X>0?'+':"") + String(
    Math.round(X*Math.pow(10, N-p-1))).replace(/(\d)/, "$1.") +
    (p>=0?"e+":"e-") + LZ(Math.abs(p)) } // All OK?


var RincB=0 // end.

