public static double calcChiasmaDist(double chromLength) {
         if (chromLength<=0.500) {
             return Double.NaN;
         }
         if (chromLength>5.0) {
             return 0.5;
         }
         double toler = 0.00001;
         double lastdiff = mdiff(chromLength,0.5);
         //first find initial minimum:
         double m1 = 10.5;
         while (mdiff(chromLength,m1)<lastdiff) {
             lastdiff = mdiff(chromLength,m1);
             m1 += 10.0;
         }
         double m2,m3;
         if (m1==10.5) {
             m2 = 5.5;
             m3 = 0.5;
         } else {
             m2 = m1 - 10.0;
             m3 = m1 - 20.0;
        }
         while (m1-m3>toler) {
             if (mdiff(chromLength,m1-0.5*(m1-m2))<mdiff(chromLength,m2)) {
                 m3 = m2;
                 m2 = m1-0.5*(m1-m2);
             }
             else if (mdiff(chromLength,m3+0.5*(m2-m3))<mdiff(chromLength,m2)) {
                 m1 = m2;
                 m2 = m3+0.5*(m2-m3);
             } else {
                 m1 = m1-0.5*(m1-m2);
                 m3 = m3+0.5*(m2-m3);
             }
         }
         return m2;
    } //calcChiasmaDist