Math.clamp method?
John Rose
john.r.rose at oracle.com
Thu Jan 26 00:06:21 UTC 2023
P.S Sorry, I botched a use case, saying x where I meant y:
```
long x = …, y = a*x*x + b*x + c;
double xf = x, yf = a*xf*xf + b*xf + c;
double yc = clamp(yf, Long.MIN_VALUE, Long.MAX_VALUE);
boolean saturated = false;
if (yc != yf) { // error processing
saturated = true; // or throw an exception
y = yc; // saturate towards the required magnitude
}
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20230125/ce09a506/attachment.htm>
More information about the core-libs-dev
mailing list