| Summary: | Fix Decimal.floor() + Decimal.ceiling() for many non-integral values | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ahmad Saleem <ahmad.saleem792> |
| Component: | Forms | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | akeerthi, cdumez, karlcow, rniwa, webkit-bug-importer, wenson_hsieh |
| Priority: | P2 | Keywords: | BrowserCompat, InRadar |
| Version: | Safari Technology Preview | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| See Also: | https://bugs.webkit.org/show_bug.cgi?id=106456 | ||
|
Description
Ahmad Saleem
2022-12-22 06:32:35 PST
Manage to have testcase - will try to do PR later today - https://jsfiddle.net/mwn0jy35/ I am closing this PR for time being because I noted that we still have other pre-requisite bugs to fix in StepUp and StepDown and closing my PR for time being with following comment: '' NOTE to myself - I am going to close this PR since there are still bugs in StepUp and StepDown, which we should fix since this might be causing this to fail. So I will look into this later, once I fix other bugs. '' PR - https://github.com/WebKit/WebKit/pull/8045 Just copying that following compiles when added to 'Decimal.cpp' (for TestWebKit API):
// Simulate core/html/forms/StepRange
class DecimalStepRange {
public:
Decimal maximum;
Decimal minimum;
Decimal step;
DecimalStepRange(const Decimal& minimum, const Decimal& maximum, const Decimal& step)
: maximum(maximum)
, minimum(minimum)
, step(step)
{
}
Decimal clampValue(Decimal value) const
{
const Decimal result = minimum + ((value - minimum) / step).round() * step;
ASSERT(result.isFinite());
return result > maximum ? result - step : result;
}
};
class Decimcal : public testing::Test {
protected:
using Sign = Decimal::Sign;
static constexpr Sign positive = Decimal::Positive;
static constexpr Sign negative = Decimal::Negative;
Decimal encode(uint64_t coefficient, int exponent, Sign sign)
{
return Decimal(sign, exponent, coefficient);
}
Decimal fromString(const String& string)
{
return Decimal::fromString(string);
}
Decimal stepDown(const String& minimum, const String& maximum, const String& step, const String& valueString, int numberOfStepTimes)
{
DecimalStepRange stepRange(fromString(minimum), fromString(maximum), fromString(step));
Decimal value = fromString(valueString);
for (int i = 0; i < numberOfStepTimes; ++i) {
value -= stepRange.step;
value = stepRange.clampValue(value);
}
return value;
}
Decimal stepUp(const String& minimum, const String& maximum, const String& step, const String& valueString, int numberOfStepTimes)
{
DecimalStepRange stepRange(fromString(minimum), fromString(maximum), fromString(step));
Decimal value = fromString(valueString);
for (int i = 0; i < numberOfStepTimes; ++i) {
value += stepRange.step;
value = stepRange.clampValue(value);
}
return value;
}
};
Committed 280189@main (c79f2cd50054): <https://commits.webkit.org/280189@main> Reviewed commits have been landed. Closing PR #29941 and removing active labels. |