get the number of digits for writing a column to the results table or the clipboard
(float[] values)
| 4412 | |
| 4413 | /** get the number of digits for writing a column to the results table or the clipboard */ |
| 4414 | static int getPrecision(float[] values) { |
| 4415 | int setDigits = Analyzer.getPrecision(); |
| 4416 | int measurements = Analyzer.getMeasurements(); |
| 4417 | boolean scientificNotation = (measurements&Measurements.SCIENTIFIC_NOTATION)!=0; |
| 4418 | if (scientificNotation) { |
| 4419 | if (setDigits<MIN_SCIENTIFIC_DIGITS) |
| 4420 | setDigits = MIN_SCIENTIFIC_DIGITS; |
| 4421 | return -setDigits; |
| 4422 | } |
| 4423 | boolean allInteger = true; |
| 4424 | float min = Float.MAX_VALUE, max = -Float.MAX_VALUE; |
| 4425 | for (int i=0; i<values.length; i++) { |
| 4426 | if ((int)values[i]!=values[i] && !Float.isNaN(values[i])) { |
| 4427 | allInteger = false; |
| 4428 | if (values[i] < min) min = values[i]; |
| 4429 | if (values[i] > max) max = values[i]; |
| 4430 | } |
| 4431 | } |
| 4432 | if (allInteger) |
| 4433 | return 0; |
| 4434 | int digits = (max - min) > 0 ? getDigits(min, max, MIN_FLOAT_PRECISION*(max-min), 15, 0) : |
| 4435 | getDigits(max, MIN_FLOAT_PRECISION*Math.abs(max), 15, 0); |
| 4436 | if (setDigits>Math.abs(digits)) |
| 4437 | digits = setDigits * (digits < 0 ? -1 : 1); //use scientific notation if needed |
| 4438 | return digits; |
| 4439 | } |
| 4440 | |
| 4441 | /** Whether a given flag 'what' is set */ |
| 4442 | @AstroImageJ(reason = "Access widen for Vector Plot saving", modified = true) |
no test coverage detected