Processing (and other Java-based languages) seem to put numbers in exponential notation when they are very, very small but not quite zero.
Example: -9.0145690E-4 is really -0.000090145690
Finding this to be a problem when trying to do things with those numbers later (like write audio sample values) I wrote a little Processing snippet that solves that problem, though does result in some loss of accuracy (since numbers are rounded up/down to 0).
Code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// the value we want to work with float verySmallFloat = -9.0145690E-4; // cast as a string so we can use match() String tempVal = str(verySmallFloat); // look for any character values (ie: "e" or "E") String[] exponentialCheck = match(tempVal, "[a-zA-Z]"); // if we find something (not null)... // ...set to 0.0 - very close to the value anyway if (exponentialCheck != null) { tempVal = "0.0"; } |