probably bad rounding

Project:Prolint Issue Tracker
Component:Rules
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

If an operation contains number 0.01 or 0.49 (or even 0.5) you should warn that these constants strongly suggest a broken approach to rounding (or bad implementation of ceil and floor functions).
Same is true for 0.001, 0.0001, 0.00001, 0.499, 0.4999 and so on.

Suggested by Tom Bascom.

The help file should tell how to write a proper round (ceil, floor) function or at least explain what goes wrong.

Greg Higgins submitted these functions :

function floor   returns integer ( input decimal ) forward.
function ceiling returns integer ( input decimal ) forward.

function floor returns integer 
  ( input ipd as decimal )
  :
  define variable tmpResult as integer no-undo.

  assign
    tmpResult = truncate ( ipd, 0 ) 
    tmpResult = 0 - ceiling ( 0 - ipd ) when ipd lt 0 
    .
  return tmpResult.
end function /* floor */.


function ceiling returns integer  
  ( input ipd as decimal )
  :
  define variable tmpResult as integer no-undo.

  assign
    tmpResult = truncate ( ipd + integer ( ipd gt truncate ( ipd, 0 ) ), 0 )
    tmpResult = 0 - floor ( 0 - ipd ) when ipd lt 0 
    .
  return tmpResult.
end function /* ceiling */.