tracker issue : CF-3587263

select a category, or use search below
(searches all categories and all time range)
Title:

MOD operator producing incorrect results

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/

Reporter/Name(from Bugbase): Paul Klein / Paul Klein (Paul@Boeing)

Created: 06/28/2013

Components: Language

Versions: 9.0.1

Failure Type:

Found In Build/Fixed In Build: 9.0.1 /

Priority/Frequency: Major / Most users will encounter

Locale/System: English / Windows 7

Vote Count: 0

Problem Description: 
Found that when using a variable containing a decimal number and a literal multiplier, the mod (or %) operator returns the incorrect results.

Steps to Reproduce: 
<cfset theValue = 1.15>
<cfoutput>#((theValue * 100) % 5)#</cfoutput>

Actual Result: 4 

Expected Result: 0

Any Workarounds: Multiply by 1000 and mod by 50 produces correct results.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3587263

Deployment Phase:	Release Candidate

External Customer Info:
External Company:  
External Customer Name: Paul@Boeing
External Customer Email:  
External Test Config: 9.0.1 Developer Edition

Attachments:

  1. June 29, 2013 00:00:00: 1_modBug.cfm

Comments:

Not really a bug: http://cfmlblog.adamcameron.me/2013/06/floating-point-bum-biting.html -- Adam
Comment by External U.
15082 | June 28, 2013 03:50:19 PM GMT
This is JDK limitation wherein 1.15 * 100 will give you 114.99999999999999 not 115. And when you do mod 114.99 , the result will be rounded interger that's 4.
Comment by Awdhesh K.
15083 | December 18, 2013 05:09:29 AM GMT
The problem is not with the Mod operator but with the floating point arithmetic and the way floating point numbers are represented in memory. http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems If you need precision, you should use PrecisionEvaluate function.
Comment by Rupesh K.
15084 | December 18, 2013 07:38:51 AM GMT