* Function to test if the input value falls with the Min / Max settings. * This uses the parsed strings for the above parseStr function. * * This function is adapted from Big.js https://github.com/MikeMcl/big.js/. Many thanks to Mike. * * @param {Big} y Big number instance
(y, x)
| 1174 | * @returns {-1|0|1} Comparison result: 0 if x=y, -1 if y>x, +1 if y<x |
| 1175 | */ |
| 1176 | static testMinMax(y, x) { |
| 1177 | const xc = x.c; |
| 1178 | const yc = y.c; |
| 1179 | let i = x.s; |
| 1180 | let j = y.s; |
| 1181 | let k = x.e; |
| 1182 | let l = y.e; |
| 1183 | |
| 1184 | // Either zero? |
| 1185 | if (!xc[0] || !yc[0]) { |
| 1186 | let result; |
| 1187 | if (!xc[0]) { |
| 1188 | result = !yc[0]?0:-j; |
| 1189 | } else { |
| 1190 | result = i; |
| 1191 | } |
| 1192 | return result; |
| 1193 | } |
| 1194 | |
| 1195 | // Signs differ? |
| 1196 | if (i !== j) { |
| 1197 | return i; |
| 1198 | } |
| 1199 | const xNeg = i < 0; |
| 1200 | |
| 1201 | // Compare exponents |
| 1202 | if (k !== l) { |
| 1203 | return (k > l ^ xNeg)?1:-1; |
| 1204 | } |
| 1205 | i = -1; |
| 1206 | k = xc.length; |
| 1207 | l = yc.length; |
| 1208 | j = (k < l) ? k : l; |
| 1209 | |
| 1210 | // Compare digit by digit |
| 1211 | for (i += 1; i < j; i += 1) { |
| 1212 | if (xc[i] !== yc[i]) { |
| 1213 | return (xc[i] > yc[i] ^ xNeg)?1:-1; |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | // Compare lengths |
| 1218 | let result; |
| 1219 | if (k === l) { |
| 1220 | result = 0; |
| 1221 | } else { |
| 1222 | result = (k > l ^ xNeg)?1:-1; |
| 1223 | } |
| 1224 | |
| 1225 | return result; |
| 1226 | } |
| 1227 | |
| 1228 | /** |
| 1229 | * Generate a random string. |
no outgoing calls
no test coverage detected