[#3962] The H2 emulation of SHR might produce rounding errors

This commit is contained in:
lukaseder 2015-01-18 12:02:50 +01:00
parent 63e9522cb1
commit c21dfd2f31

View File

@ -171,10 +171,13 @@ class Expression<T> extends AbstractFunction<T> {
// Many dialects don't support shifts. Use multiplication/division instead
else if (SHL == operator && asList(H2, HSQLDB).contains(family)) {
return lhs.mul(DSL.power(two(), rhsAsNumber()));
return lhs.mul((Field<? extends Number>) DSL.power(two(), rhsAsNumber()).cast(lhs));
}
// [#3962] This emulation is expensive. If this is emulated, BitCount should
// use division instead of SHR directly
else if (SHR == operator && asList(H2, HSQLDB).contains(family)) {
return lhs.div(DSL.power(two(), rhsAsNumber()));
return lhs.div((Field<? extends Number>) DSL.power(two(), rhsAsNumber()).cast(lhs));
}
// Some dialects support shifts as functions