You are reading a single comment by @asez73 and its replies. Click here to read the full conversation.
  • Thanks,
    Yes, I had forgotten about decimals beeing rounded somewhere when transformed into binaries.

    So I tested the second solution and it works.

    I totally agree with the no bug approach. The trick is that it's a silent killer. As well as dynamic typing is indeed.

    However, the value of v is continuous (risk level in probability) so the exact comparison done by Array.indexOf was not my need.

    I finally settled on Array.findIndex as I can get an index through a comparison function even if the value is really not in the array but rather in between values in the array. My array is sorted in increase order.
    And this came from your first answer. tab1mAlpha.findIndex(a=>Math.abs(a-v)<0.­000001)

    This page provides the formulas and statistics tables from which I extracted the 2 arrays below...
    That gave me:

    // approximately computes the xhi2 of 2 degrees of liberty value for alpha risk
      function xhi2_2(alphaRisk) { 
            var idx = [0.05, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9, 0.95, 0.99, 0.999].findIndex(elt => elt>=(1-alphaRisk));
        return [0.10, 0.21, 0.45, 0.71, 1.39, 2.41, 3.22, 4.61, 5.99, 9.21, 13.82][idx];
      }
     
    

    Thank's again for your reactivity and commitment to understand our questions!

About

Avatar for asez73 @asez73 started