MCPcopy Create free account
hub / github.com/choosehappy/QuickAnnotator / isValidForStep

Function isValidForStep

static/js/angular.js:26869–26898  ·  view source on GitHub ↗
(viewValue, stepBase, step)

Source from the content-addressed store, hash-verified

26867}
26868
26869function isValidForStep(viewValue, stepBase, step) {
26870 // At this point `stepBase` and `step` are expected to be non-NaN values
26871 // and `viewValue` is expected to be a valid stringified number.
26872 var value = Number(viewValue);
26873
26874 var isNonIntegerValue = !isNumberInteger(value);
26875 var isNonIntegerStepBase = !isNumberInteger(stepBase);
26876 var isNonIntegerStep = !isNumberInteger(step);
26877
26878 // Due to limitations in Floating Point Arithmetic (e.g. `0.3 - 0.2 !== 0.1` or
26879 // `0.5 % 0.1 !== 0`), we need to convert all numbers to integers.
26880 if (isNonIntegerValue || isNonIntegerStepBase || isNonIntegerStep) {
26881 var valueDecimals = isNonIntegerValue ? countDecimals(value) : 0;
26882 var stepBaseDecimals = isNonIntegerStepBase ? countDecimals(stepBase) : 0;
26883 var stepDecimals = isNonIntegerStep ? countDecimals(step) : 0;
26884
26885 var decimalCount = Math.max(valueDecimals, stepBaseDecimals, stepDecimals);
26886 var multiplier = Math.pow(10, decimalCount);
26887
26888 value = value * multiplier;
26889 stepBase = stepBase * multiplier;
26890 step = step * multiplier;
26891
26892 if (isNonIntegerValue) value = Math.round(value);
26893 if (isNonIntegerStepBase) stepBase = Math.round(stepBase);
26894 if (isNonIntegerStep) step = Math.round(step);
26895 }
26896
26897 return (value - stepBase) % step === 0;
26898}
26899
26900function numberInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse) {
26901 badInputChecker(scope, element, attr, ctrl, 'number');

Callers 2

numberInputTypeFunction · 0.85
rangeInputTypeFunction · 0.85

Calls 2

isNumberIntegerFunction · 0.85
countDecimalsFunction · 0.85

Tested by

no test coverage detected