Project

Profile

Help

Revision ab5e123a

Added by Michael Kay over 7 years ago

Fix bug 2127 (rounding)

View differences:

latest9.5/hej/net/sf/saxon/value/DoubleValue.java
238 238
            return this;    // handles the negative zero case
239 239
        }
240 240
        
241
        if (value == -0.0) {
242
            return this;    // handles the negative zero case
243
        }
244
        
245
        if (value >= -0.5 && value < 0.0) {
246
            return new DoubleValue(-0.0);
247
        }
248
        
249 241
        if (scale==0 && value > Long.MIN_VALUE && value < Long.MAX_VALUE) {
242
            if (value >= -0.5 && value < 0.0) {
243
                return new DoubleValue(-0.0);
244
            }
250 245
            return new DoubleValue(Math.round(value));
251 246
        }
252 247

  
......
262 257
            return new DoubleValue(dec.doubleValue());
263 258
        }
264 259

  
265
        // Now apply any rounding needed, using the "round half to even" rule***CHANGE
260
        // Now apply any rounding needed, using the "round half to even" rule
266 261

  
267 262
        double rem = d % 10;
268 263
        if (rem >= 5) {
latest9.5/hej/net/sf/saxon/value/FloatValue.java
223 223
    */
224 224

  
225 225
    public NumericValue round(int scale) {
226
        if (Float.isNaN(value)) return this;
227
        if (Float.isInfinite(value)) return this;
228
        if (value==0.0) return this;    // handles the negative zero case
229
        if (value >= -0.5 && value < 0.0) return new FloatValue(-0.0f);
230
        if (scale==0 && value > Integer.MIN_VALUE && value < Integer.MAX_VALUE) {
231
            return new FloatValue((float)Math.round(value));
226
        if (Float.isNaN(value)) {
227
            return this;
228
        }
229
        if (Float.isInfinite(value)) {
230
            return this;
231
        }
232
        if (value == 0.0) {
233
            return this;    // handles the negative zero case
234
        }
235

  
236
        if (scale == 0 && value > Integer.MIN_VALUE && value < Integer.MAX_VALUE) {
237
            if (value >= -0.5 && value < 0.0) {
238
                return new FloatValue(-0.0f);
239
            }
240
            return new FloatValue((float) Math.round(value));
232 241
        }
233 242
        DoubleValue d = new DoubleValue(getDoubleValue());
234
        d = (DoubleValue)d.round(scale);
243
        d = (DoubleValue) d.round(scale);
235 244
        return new FloatValue(d.getFloatValue());
236 245
    }
237 246

  

Also available in: Unified diff