[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-21 Thread Joel Cass

I remember someone raising this issue yonks ago in CF 4.5 or something

A quick fix: #round((1024-1024.1)*10)/10#

On Wed, 2007-02-21 at 13:38 +1100, Robin Hilliard wrote:
  What exactly is a 'CF number'?
 
 All simple CF variables are stored as strings.  When used as numbers  
 in an expression they have 12 significant digits according to the  
 documentation, which I assume is a java Float (a Double would have  
 more).
 
 As for a solution in CFML, I wouldn't mind an optional second  
 argument to round(), fix(), ceil() etc that defaulted to 0 and  
 specified the number of decimal places to round to (Excel VBA has this).
 
 I imagine that changing the type used to represent numbers internally  
 or building rounding into all number handling may impact legacy cf  
 apps and server performance - I would be against a change if either  
 were true.
 
 Cheers,
 Robin
 
 
 __
 
 Robin Hilliard
 Director - RocketBoots Pty Ltd
 Consulting . Recruitment . Software Licensing . Training
 http://www.rocketboots.com.au
 
 For schedule/availability call Pamela Higgins:
 w+61 7 5451 0362
 m+61 419 677 151
 f+61 3 9923 6261
 e[EMAIL PROTECTED]
 
 or Direct:
 m+61 418 414 341
 e[EMAIL PROTECTED]
 
 
 On 21/02/2007, at 10:32 AM, Rod Higgins wrote:
 
 
  Hi Robin,
 
  What exactly is a 'CF number'? It seems to be CF can store it as a  
  string or
  a double / float depending on the way it is constructed or what  
  methods are
  used on the var. I agree with Gareth in that CF needs to make untyped
  numbers in CF more consistent. The values generated from Gareth's code
  shouldn't happen and no I don't agree with the opinion it is a  
  fault / known
  issue of the Java language, it is simply the way CF was written to  
  use Java.
  They decided to go with a smaller memory footprint for storing numeric
  values. This is a very annoying issue when dealing with very small  
  numbers
  in CF and has driven me nuts plenty of times before.
 
  Obviously using BigDecimal for every numeric in CF would use too  
  much memory
  but maybe some option for the construction of 'CF numbers' so  
  developers can
  choose to be more precise.
 
  Rod
 
  
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-20 Thread Steve Armstrong
Andrew,

To say that it has nothing to do with ColdFusion is incorrect - as a
developer has come across the issue developing an application using
ColdFusion.  Sure it is an 'across the board of programming languages' issue
- but that doesn't mean that Adobe cannot note the issue in its
documentation and training guides - which is what Gareth was suggesting.
Robin's suggestion looks to be the neatest solution so far.

Steve


On 2/20/07, Andrew Scott [EMAIL PROTECTED] wrote:

  Gareth,



 Again you have been politely told it has nothing to do with Coldfusion, if
 you are aware how Coldfusion works under the hood, then accept that it is a
 know problem not a bug then deal with it and move on.



 Complaining about CF is not going to change the fact that Java has the
 issue and not CF.





 Andrew Scott
 Senior Coldfusion Developer
 Aegeon Pty. Ltd.
 www.aegeon.com.au
 Phone: +613  8676 4223
 Mobile: 0404 998 273





 *From:* cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] *On
 Behalf Of *Gareth Edwards
 *Sent:* Tuesday, 20 February 2007 2:40 PM
 *To:* cfaussie@googlegroups.com
 *Subject:* [cfaussie] Re: Strange calculation behavior on CF 7.02



 Indicating you know how Coldfusion works really proves nothing, I'm quite
 aware of how it all works. I'm just annoyed that Coldfusion doesn't deal
 with this situation better than it does.

 Once again, Javascript, although not strictly typed, is a typed language.
 If I could type in Coldfusion I would.

 Also, Coldfusion should get this one right, but it doesn't cfdump
 var=#1024.00-1024.10# returns -0.0

 Cheers
 Gareth.



 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-20 Thread Robin Hilliard

Hi Rod,

Big Decimal has far more precision than a CF number (only 12  
significant digits) and has built in rounding - you can set the  
precision with it's setScale(scale, rounding-mode) method.

One point to note if you are using BigDecimal - you should use the  
string constructor i.e. init(0.1) because otherwise ColdFusion will  
convert the literal 0.1 to a ColdFusion number (with it's more  
limited precision) before passing it to Java.

Robin

__

Robin Hilliard
Director - RocketBoots Pty Ltd
Consulting . Recruitment . Software Licensing . Training
http://www.rocketboots.com.au

For schedule/availability call Pamela Higgins:
w+61 7 5451 0362
m+61 419 677 151
f+61 3 9923 6261
e[EMAIL PROTECTED]

or Direct:
m+61 418 414 341
e[EMAIL PROTECTED]


On 20/02/2007, at 6:43 PM, rod higgins wrote:


 If you use the java class and methods that handle these types of
 numbers I don't see the problem??

 cfloop from=1 to=1000 index=i
   cfset diff = CreateObject(Java, java.math.BigDecimal).init(0.1)
 cfset a = CreateObject(Java,
 java.math.BigDecimal).init(RandRange(100,1))
 cfset b = CreateObject(Java,
 java.math.BigDecimal).init(a*2)
 cfset c = CreateObject(Java,
 java.math.BigDecimal).init(val(a))
   cfset c = c.add(diff)
   cfset d = a.subtract(b).add(c)
 cfoutput#a#-#b#+#c# = #d#br //cfoutput
 /cfloop

 It seems CF is using some sort of toString() value during the
 calculation at some stage??

 hth
 Rod

 On Feb 20, 12:04 pm, Gareth Edwards [EMAIL PROTECTED] wrote:
 If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't  
 know)

 Run this script below, and tell me if you get the same results for  
 each
 line. The way I see it, d should equal 0.1 on every row. But this  
 isn't
 the case. Is this a bug introduced by Coldfusion 7.02?

 cfset a = 0
 cfset b = 0
 cfset c = 0

 cfloop from=1 to=1000 index=i
 cfset a = RandRange(1,2)
 cfset b = a*2
 cfset c = #ListFirst(Trim(a),.)#.00
 cfset c = c + 0.1
 cfset d = a - val(b) + val(c)
 cfoutput#d#br //cfoutput
 /cfloop

 Cheers
 Gareth.


 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-20 Thread Andrew Scott
Steve,

 

Gareth stated and I quote, It hasn't been a problem previously, why would
it be a problem now? CFML is not a strong typed language and there for
should evaluate situations like this correctly.

 

So as you see I am correct by saying it has nothing to do with CF, but yes I
agree about some form of docs etc. And to expect CF not to have this problem
is where he got our backs up, not that it should have been documented
somewhere but his quote says it all.

 

 



Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613  8676 4223
Mobile: 0404 998 273

From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Steve Armstrong
Sent: Tuesday, 20 February 2007 8:47 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02

 

Andrew,

 

To say that it has nothing to do with ColdFusion is incorrect - as a
developer has come across the issue developing an application using
ColdFusion.  Sure it is an 'across the board of programming languages' issue
- but that doesn't mean that Adobe cannot note the issue in its
documentation and training guides - which is what Gareth was suggesting.
Robin's suggestion looks to be the neatest solution so far. 

 

Steve

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-20 Thread Andrew Scott
Hmm, interesting you used to be able to select that option in previous
versionJ



Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613  8676 4223
Mobile: 0404 998 273


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-20 Thread Robin Hilliard

 What exactly is a 'CF number'?

All simple CF variables are stored as strings.  When used as numbers  
in an expression they have 12 significant digits according to the  
documentation, which I assume is a java Float (a Double would have  
more).

As for a solution in CFML, I wouldn't mind an optional second  
argument to round(), fix(), ceil() etc that defaulted to 0 and  
specified the number of decimal places to round to (Excel VBA has this).

I imagine that changing the type used to represent numbers internally  
or building rounding into all number handling may impact legacy cf  
apps and server performance - I would be against a change if either  
were true.

Cheers,
Robin


__

Robin Hilliard
Director - RocketBoots Pty Ltd
Consulting . Recruitment . Software Licensing . Training
http://www.rocketboots.com.au

For schedule/availability call Pamela Higgins:
w+61 7 5451 0362
m+61 419 677 151
f+61 3 9923 6261
e[EMAIL PROTECTED]

or Direct:
m+61 418 414 341
e[EMAIL PROTECTED]


On 21/02/2007, at 10:32 AM, Rod Higgins wrote:


 Hi Robin,

 What exactly is a 'CF number'? It seems to be CF can store it as a  
 string or
 a double / float depending on the way it is constructed or what  
 methods are
 used on the var. I agree with Gareth in that CF needs to make untyped
 numbers in CF more consistent. The values generated from Gareth's code
 shouldn't happen and no I don't agree with the opinion it is a  
 fault / known
 issue of the Java language, it is simply the way CF was written to  
 use Java.
 They decided to go with a smaller memory footprint for storing numeric
 values. This is a very annoying issue when dealing with very small  
 numbers
 in CF and has driven me nuts plenty of times before.

 Obviously using BigDecimal for every numeric in CF would use too  
 much memory
 but maybe some option for the construction of 'CF numbers' so  
 developers can
 choose to be more precise.

 Rod

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-20 Thread Andrew Scott
LOL, that was sent to the wrong list. Sorry for the confusion.



Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613  8676 4223
Mobile: 0404 998 273

From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Gareth Edwards
Sent: Wednesday, 21 February 2007 1:41 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02

 

Andrew,

What option?

Cheers
Gareth.

Andrew Scott wrote: 

Hmm, interesting you used to be able to select that option in previous
versionJ



Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613  8676 4223
Mobile: 0404 998 273

 




 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Barry Beattie

not having a working CF server handy at the moment to test, I'm just curious

you're not getting grief with treating strings as numbers, are you?

perhaps a val( #ListFirst(Trim(a),.)#.00 ) is needed?

just a quick thought
b

On 2/20/07, Gareth Edwards [EMAIL PROTECTED] wrote:

 If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

 Run this script below, and tell me if you get the same results for each
 line. The way I see it, d should equal 0.1 on every row. But this isn't
 the case. Is this a bug introduced by Coldfusion 7.02?

 cfset a = 0
 cfset b = 0
 cfset c = 0

 cfloop from=1 to=1000 index=i
 cfset a = RandRange(1,2)
 cfset b = a*2
 cfset c = #ListFirst(Trim(a),.)#.00
 cfset c = c + 0.1
 cfset d = a - val(b) + val(c)
 cfoutput#d#br //cfoutput
 /cfloop

 Cheers
 Gareth.

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





If it were a string, and it was having troubles the end result
should be consistent. Check this out.

9314-18628+9314.1 = 0.1
4730-9460+4730.1 = 0.1
9913-19826+9913.1 = 0.1
3913-7826+3913.1 = 0.0
6770-13540+6770.1 = 0.1
3000-6000+3000.1 = 0.0

Cheers
Gareth.

Barry Beattie wrote:

  not having a working CF server handy at the moment to test, I'm just curious

you're not getting grief with treating strings as numbers, are you?

perhaps a val( "#ListFirst(Trim(a),".")#.00" ) is needed?

just a quick thought
b

On 2/20/07, Gareth Edwards [EMAIL PROTECTED] wrote:
  
  
If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

Run this script below, and tell me if you get the same results for each
line. The way I see it, d should equal 0.1 on every row. But this isn't
the case. Is this a bug introduced by Coldfusion 7.02?

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from="1" to="1000" index="i"
cfset a = RandRange(1,2)
cfset b = a*2
cfset c = "#ListFirst(Trim(a),".")#.00"
cfset c = c + 0.1
cfset d = a - val(b) + val(c)
cfoutput#d#br //cfoutput
/cfloop

Cheers
Gareth.


  
  


  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





Just an update... the new code below does the same thing.

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from="1" to="1000" index="i"
 cfset a = RandRange(100,1)
 cfset b = a*2
 cfset c = val("#ListFirst(Trim(a),".")#.00")
 cfset c = c + 0.1
 cfset d = a - b + c
 cfoutput#a#-#b#+#c# = #d#br //cfoutput
/cfloop

Barry Beattie wrote:

  not having a working CF server handy at the moment to test, I'm just curious

you're not getting grief with treating strings as numbers, are you?

perhaps a val( "#ListFirst(Trim(a),".")#.00" ) is needed?

just a quick thought
b

On 2/20/07, Gareth Edwards [EMAIL PROTECTED] wrote:
  
  
If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

Run this script below, and tell me if you get the same results for each
line. The way I see it, d should equal 0.1 on every row. But this isn't
the case. Is this a bug introduced by Coldfusion 7.02?

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from="1" to="1000" index="i"
cfset a = RandRange(1,2)
cfset b = a*2
cfset c = "#ListFirst(Trim(a),".")#.00"
cfset c = c + 0.1
cfset d = a - val(b) + val(c)
cfoutput#d#br //cfoutput
/cfloop

Cheers
Gareth.


  
  


  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Ryan Sabir


They looks like pretty standard floating point rounding errors. You get them in 
any programming language where you deal with fractions.

The trick is to expect that this will happen and plan your application around 
it.


 -Original Message-
 From: cfaussie@googlegroups.com 
 [mailto:[EMAIL PROTECTED] On Behalf Of Gareth Edwards
 Sent: Tuesday, 20 February 2007 12:05 PM
 To: CFAussie Mailing List
 Subject: [cfaussie] Strange calculation behavior on CF 7.02
 
 
 If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)
 
 Run this script below, and tell me if you get the same 
 results for each line. The way I see it, d should equal 0.1 
 on every row. But this isn't the case. Is this a bug 
 introduced by Coldfusion 7.02?
 
 cfset a = 0
 cfset b = 0
 cfset c = 0
 
 cfloop from=1 to=1000 index=i
 cfset a = RandRange(1,2)
 cfset b = a*2
 cfset c = #ListFirst(Trim(a),.)#.00
 cfset c = c + 0.1
 cfset d = a - val(b) + val(c)
 cfoutput#d#br //cfoutput
 /cfloop
 
 Cheers
 Gareth.
 
  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





It hasn't been a problem previously, why would it be a problem now?
CFML is not a strong typed language and there for should evaluate
situations like this correctly.

Cheers
Gareth.

Ryan Sabir wrote:

  
They looks like pretty standard floating point rounding errors. You get them in any programming language where you deal with fractions.

The trick is to expect that this will happen and plan your application around it.


  
  
-Original Message-
From: cfaussie@googlegroups.com 
[mailto:cfaussie@googlegroups.com] On Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 12:05 PM
To: CFAussie Mailing List
Subject: [cfaussie] Strange calculation behavior on CF 7.02


If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

Run this script below, and tell me if you get the same 
results for each line. The way I see it, d should equal 0.1 
on every row. But this isn't the case. Is this a bug 
introduced by Coldfusion 7.02?

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from="1" to="1000" index="i"
cfset a = RandRange(1,2)
cfset b = a*2
cfset c = "#ListFirst(Trim(a),".")#.00"
cfset c = c + 0.1
cfset d = a - val(b) + val(c)
cfoutput#d#br //cfoutput
/cfloop

Cheers
Gareth.


  
  



  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Ryan Sabir
I just tried it on an old CF5 server and it did the same thing.
 
It's nothing to do with data typing. The underlying calculation to work out 
what X * 0.1 is, will always have some degree of rounding error due to the way 
those numbers are stored in memory.
 
 




From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Gareth 
Edwards
Sent: Tuesday, 20 February 2007 12:37 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02


It hasn't been a problem previously, why would it be a problem now? CFML is not 
a strong typed language and there for should evaluate situations like this 
correctly.

Cheers
Gareth.

Ryan Sabir wrote: 
They looks like pretty standard floating point rounding errors. You get them in 
any programming language where you deal with fractions.

The trick is to expect that this will happen and plan your application around 
it.


  
-Original Message-
From: cfaussie@googlegroups.com 
[mailto:[EMAIL PROTECTED] On Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 12:05 PM
To: CFAussie Mailing List
Subject: [cfaussie] Strange calculation behavior on CF 7.02


If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

Run this script below, and tell me if you get the same 
results for each line. The way I see it, d should equal 0.1 
on every row. But this isn't the case. Is this a bug 
introduced by Coldfusion 7.02?

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from=1 to=1000 index=i
cfset a = RandRange(1,2)
cfset b = a*2
cfset c = #ListFirst(Trim(a),.)#.00
cfset c = c + 0.1
cfset d = a - val(b) + val(c)
cfoutput#d#br //cfoutput
/cfloop

Cheers
Gareth.






  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





What about 7.01 or 7.00? or 6.1 or 6? CF5 is not a fair comparison.

Cheers
Gareth.

Ryan Sabir wrote:

  
  
  
  I just tried it on anold CF5 server and it
did the same thing.
  
  It's nothing to do with data typing. The
underlying calculation to work out whatX * 0.1 is, will always have
some degree of rounding error due to the way those numbers are stored
in memory.
  
  
  
  

 From:
cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On
Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 12:37 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF
7.02


It hasn't been a problem previously, why would it be a problem now?
CFML is not a strong typed language and there for should evaluate
situations like this correctly.

Cheers
Gareth.

Ryan Sabir wrote:

  They looks like pretty standard floating point rounding errors. You get them in any programming language where you deal with fractions.

The trick is to expect that this will happen and plan your application around it.


  
  
-Original Message-
From: cfaussie@googlegroups.com 
[mailto:cfaussie@googlegroups.com] On Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 12:05 PM
To: CFAussie Mailing List
Subject: [cfaussie] Strange calculation behavior on CF 7.02


If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

Run this script below, and tell me if you get the same 
results for each line. The way I see it, d should equal 0.1 
on every row. But this isn't the case. Is this a bug 
introduced by Coldfusion 7.02?

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from="1" to="1000" index="i"
cfset a = RandRange(1,2)
cfset b = a*2
cfset c = "#ListFirst(Trim(a),".")#.00"
cfset c = c + 0.1
cfset d = a - val(b) + val(c)
cfoutput#d#br //cfoutput
/cfloop

Cheers
Gareth.


  
  



  





  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Brett Payne-Rhodes

AFAIK this has always been an issue. I usually deal with it by using integers 
where possible, as in store and calculate prices in cents not dollars - don't 
have much call for anything more complicated than that.

B)


Gareth Edwards wrote:
 What about 7.01 or 7.00? or 6.1 or 6? CF5 is not a fair comparison.
 
 Cheers
 Gareth.
 
 Ryan Sabir wrote:
 I just tried it on an old CF5 server and it did the same thing.
  
 It's nothing to do with data typing. The underlying calculation to 
 work out what X * 0.1 is, will always have some degree of rounding 
 error due to the way those numbers are stored in memory.
  
  

 
 *From:* cfaussie@googlegroups.com
 [mailto:[EMAIL PROTECTED] *On Behalf Of *Gareth Edwards
 *Sent:* Tuesday, 20 February 2007 12:37 PM
 *To:* cfaussie@googlegroups.com
 *Subject:* [cfaussie] Re: Strange calculation behavior on CF 7.02

 It hasn't been a problem previously, why would it be a problem
 now? CFML is not a strong typed language and there for should
 evaluate situations like this correctly.

 Cheers
 Gareth.

 Ryan Sabir wrote:
 They looks like pretty standard floating point rounding errors. You get 
 them in any programming language where you deal with fractions.

 The trick is to expect that this will happen and plan your application 
 around it.


   
 -Original Message-
 From: cfaussie@googlegroups.com 
 [mailto:[EMAIL PROTECTED] On Behalf Of Gareth Edwards
 Sent: Tuesday, 20 February 2007 12:05 PM
 To: CFAussie Mailing List
 Subject: [cfaussie] Strange calculation behavior on CF 7.02


 If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

 Run this script below, and tell me if you get the same 
 results for each line. The way I see it, d should equal 0.1 
 on every row. But this isn't the case. Is this a bug 
 introduced by Coldfusion 7.02?

 cfset a = 0
 cfset b = 0
 cfset c = 0

 cfloop from=1 to=1000 index=i
 cfset a = RandRange(1,2)
 cfset b = a*2
 cfset c = #ListFirst(Trim(a),.)#.00
 cfset c = c + 0.1
 cfset d = a - val(b) + val(c)
 cfoutput#d#br //cfoutput
 /cfloop

 Cheers
 Gareth.

 




   




 
 
  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Ryan Sabir
Just remembered I had a 6.1 server lying around. And yes it did the same thing:
 
0.1
0.1
0.1
0.09985
0.09985
0.1
0.09985
0.1
0.1
0.09985
0.1
0.09985
0.09985
0.09985
0.1
0.1
0.1
0.1
0.09985
0.1

 
There's lots of references to this common problem, e.g.:
http://www.regdeveloper.co.uk/2006/08/12/floating_point_approximation/
 
As to why you are seeing different results in different CF versions... not 
sure. But if you code to expect the rounding errors, then it won't matter.
 




From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Gareth 
Edwards
Sent: Tuesday, 20 February 2007 12:53 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02


What about 7.01 or 7.00? or 6.1 or 6? CF5 is not a fair comparison.

Cheers
Gareth.

Ryan Sabir wrote: 
I just tried it on an old CF5 server and it did the same thing.
 
It's nothing to do with data typing. The underlying calculation to work out 
what X * 0.1 is, will always have some degree of rounding error due to the way 
those numbers are stored in memory.
 
 




From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Gareth 
Edwards
Sent: Tuesday, 20 February 2007 12:37 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02


It hasn't been a problem previously, why would it be a problem now? CFML is not 
a strong typed language and there for should evaluate situations like this 
correctly.

Cheers
Gareth.

Ryan Sabir wrote: 
They looks like pretty standard floating point rounding errors. You get them in 
any programming language where you deal with fractions.

The trick is to expect that this will happen and plan your application around 
it.


  
-Original Message-
From: cfaussie@googlegroups.com 
[mailto:[EMAIL PROTECTED] On Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 12:05 PM
To: CFAussie Mailing List
Subject: [cfaussie] Strange calculation behavior on CF 7.02


If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

Run this script below, and tell me if you get the same 
results for each line. The way I see it, d should equal 0.1 
on every row. But this isn't the case. Is this a bug 
introduced by Coldfusion 7.02?

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from=1 to=1000 index=i
cfset a = RandRange(1,2)
cfset b = a*2
cfset c = #ListFirst(Trim(a),.)#.00
cfset c = c + 0.1
cfset d = a - val(b) + val(c)
cfoutput#d#br //cfoutput
/cfloop

Cheers
Gareth.






  








--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





So why the mixed result?

Cheers
Gareth.

Ryan Sabir wrote:

  
  
  
  Just remembered I had a 6.1 server lying
around. And yes it did the same thing:
  
  0.1
0.1
0.1
0.09985
0.09985
0.1
0.09985
0.1
0.1
0.09985
0.1
0.09985
0.09985
0.09985
0.1
0.1
0.1
0.1
0.09985
0.1
  
  
  There's
lots of references to this common problem, e.g.:
  http://www.regdeveloper.co.uk/2006/08/12/floating_point_approximation/
  
  As
to why you are seeing different results in different CF versions... not
sure. But if you code to expect the rounding errors, then it won't
matter.
  
  
  
  

 From:
cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On
Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 12:53 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF
7.02


What about 7.01 or 7.00? or 6.1 or 6? CF5 is not a fair comparison.

Cheers
Gareth.

Ryan Sabir wrote:

  
  I just tried it on anold CF5 server and it
did the same thing.
  
  It's nothing to do with data typing. The
underlying calculation to work out whatX * 0.1 is, will always have
some degree of rounding error due to the way those numbers are stored
in memory.
  
  
  
  

 From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com]
On Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 12:37 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on
CF 7.02


It hasn't been a problem previously, why would it be a problem now?
CFML is not a strong typed language and there for should evaluate
situations like this correctly.

Cheers
Gareth.

Ryan Sabir wrote:

  They looks like pretty standard floating point rounding errors. You get them in any programming language where you deal with fractions.

The trick is to expect that this will happen and plan your application around it.


  
  
-Original Message-
From: cfaussie@googlegroups.com 
[mailto:cfaussie@googlegroups.com] On Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 12:05 PM
To: CFAussie Mailing List
Subject: [cfaussie] Strange calculation behavior on CF 7.02


If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

Run this script below, and tell me if you get the same 
results for each line. The way I see it, d should equal 0.1 
on every row. But this isn't the case. Is this a bug 
introduced by Coldfusion 7.02?

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from="1" to="1000" index="i"
cfset a = RandRange(1,2)
cfset b = a*2
cfset c = "#ListFirst(Trim(a),".")#.00"
cfset c = c + 0.1
cfset d = a - val(b) + val(c)
cfoutput#d#br //cfoutput
/cfloop

Cheers
Gareth.


  
  



  





  





  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





Now you show me in the Coldfusion Documentation where this is
outlined as a known issue?

Cheers
Gareth.

Ryan Sabir wrote:

  
  
  
  
  
  Doesn't really matter why... Maybe
there's a gremlin that lives in the last 0.00015 of every
floating point number. Every now and then he will wake up and mess up
your number, and sometime's he'll stay asleep. Write your code
expecting he might pop round for a
visit, and he won't bother you.
  
  If you
really want to find out why, then you'll need to do some pretty hard
core maths to work out how fractions are represented in binary. I
prefer to leave that to the geeks who work at Intel and AMD while I get
on with my work.
  
  

  

 From:
cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On
Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 1:11 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF
7.02


So why the mixed result?

Cheers
Gareth.

Ryan Sabir wrote:

  
  Just remembered I had a 6.1 server lying
around. And yes it did the same thing:
  
  0.1
0.1
0.1
0.09985
0.09985
0.1
0.09985
0.1
0.1
0.09985
0.1
0.09985
0.09985
0.09985
0.1
0.1
0.1

  
  
  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Andrew Scott
Gareth,

 

You have been politely told that this is not a bug, and it does occur on
every know programming language that I have ever used.

 



Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613  8676 4223
Mobile: 0404 998 273

From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Gareth Edwards
Sent: Tuesday, 20 February 2007 1:42 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02

 

Now you show me in the Coldfusion Documentation where this is outlined
as a known issue?

Cheers
Gareth.

Ryan Sabir wrote: 

 

Doesn't really matter why... Maybe there's a gremlin that lives in the last
0.00015 of every floating point number. Every now and then he will
wake up and mess up your number, and sometime's he'll stay asleep. Write
your code expecting he might pop round for a visit, and he won't bother you.

 

If you really want to find out why, then you'll need to do some pretty hard
core maths to work out how fractions are represented in binary. I prefer to
leave that to the geeks who work at Intel and AMD while I get on with my
work.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





I think your missing the point Andrew... Coldfusion is not strongly
typed, so one would assume that a simple calculation between a integer
and a decimal would come back correctly.

Cheers
Gareth

Andrew Scott wrote:

  
  
  

  
  Gareth,
  
  You
have been politely told that this is not a bug, and it does
occur on every know programming language that I have ever used.
  
  
  
Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
  www.aegeon.com.au
Phone:+613 8676 4223
  Mobile:
0404 998
273
  
  
  From:
cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On
Behalf Of Gareth
Edwards
  Sent: Tuesday, 20 February 2007 1:42 PM
  To: cfaussie@googlegroups.com
  Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02
  
  
  
  Now you show me in the Coldfusion
Documentation where
this is outlined as a known issue?
  
Cheers
Gareth.
  
Ryan Sabir wrote: 
  
  Doesn't
really
matter why... Maybe there's a gremlin that lives in the last
0.00015 of
every floating point number. Every now and then he will wake up and
mess up
your number, and sometime's he'll stay asleep. Write your code
expecting he
might pop round for a visit, and he won't bother you.
  
  
  If
you really want
to find out why, then you'll need to do some pretty hard core maths to
work out
how fractions are represented in binary. I prefer to leave that to the
geeks
who work at Intel and AMD while I get on with my work.
  
  
  
  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Ryan Sabir
Here's a technote from Sun, regarding Java.. the underlying subsystem of 
ColdFusion:
 
http://java.sun.com/developer/JDCTechTips/2001/tt0807.html
 
I wouldn't expect this to be in the CF documentation. It's not Adobe's problem.



From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Gareth 
Edwards
Sent: Tuesday, 20 February 2007 1:42 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02


Now you show me in the Coldfusion Documentation where this is outlined as a 
known issue?

Cheers
Gareth.

Ryan Sabir wrote: 
 
Doesn't really matter why... Maybe there's a gremlin that lives in the last 
0.00015 of every floating point number. Every now and then he will wake 
up and mess up your number, and sometime's he'll stay asleep. Write your code 
expecting he might pop round for a visit, and he won't bother you.
 
If you really want to find out why, then you'll need to do some pretty hard 
core maths to work out how fractions are represented in binary. I prefer to 
leave that to the geeks who work at Intel and AMD while I get on with my work.

 


From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Gareth 
Edwards
Sent: Tuesday, 20 February 2007 1:11 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02


So why the mixed result?

Cheers
Gareth.

Ryan Sabir wrote: 
Just remembered I had a 6.1 server lying around. And yes it did the same thing:
 
0.1
0.1
0.1
0.09985
0.09985
0.1
0.09985
0.1
0.1
0.09985
0.1
0.09985
0.09985
0.09985
0.1
0.1
0.1






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





Who's missing my point? One shouldn't have to worry about typing in
Coldfusion. If in an evaluation a decimal is found amongst integers, it
should still calculate correctly. Whether it does this by making the
other values decimals, I don't care, but Coldfusion is a plain English
language, and it not typed, there for if one reads cfdump
var="#1024-1024.1#" as -0.1 I think that is what coldfusion should
return.

Cheers
Gareth.

Ryan Sabir wrote:

  
  
  
  Here's a technote from Sun, regarding Java..
the underlying subsystem of ColdFusion:
  
  http://java.sun.com/developer/JDCTechTips/2001/tt0807.html
  
  I
wouldn't expect this to be in the CF documentation. It's not Adobe's
problem.
  
  

 From:
cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On
Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 1:42 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF
7.02


Now you show me in the Coldfusion Documentation where this is
outlined as a known issue?

Cheers
Gareth.

Ryan Sabir wrote:

  
  
  
  Doesn't really matter why... Maybe
there's a gremlin that lives in the last 0.00015 of every
floating point number. Every now and then he will wake up and mess up
your number, and sometime's he'll stay asleep. Write your code
expecting he might pop round for a
visit, and he won't bother you.
  
  If you
really want to find out why, then you'll need to do some pretty hard
core maths to work out how fractions are represented in binary. I
prefer to leave that to the geeks who work at Intel and AMD while I get
on with my work.
  
  

  

 From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com]
On Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 1:11 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on
CF 7.02


So why the mixed result?

Cheers
Gareth.

Ryan Sabir wrote:

  
  Just remembered I had a 6.1 server lying
around. And yes it did the same thing:
  
  0.1
0.1
0.1
0.09985
0.09985
0.1
0.09985
0.1
0.1
0.09985
0.1
0.09985
0.09985
0.09985
0.1
0.1
0.1

  
  
  





  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Andrew Scott
Gareth,

 

I think you are missing the point, whether coldfusion is a typed language or
not. The underlying technology of CF has a problem with what your asking.

 

Now just a fresher in how CF works for you, Coldfusion will always try to
treat everything as a numerical value first if this throws an exception it
is then treated as a string. Now because CF has that, that doesn't mean that
I see variable=1024-1024.1 and treat the example as you are asking why.
Because of the problem that Ryan has stated to you, and it doesn't matter
what language you are in, it will be the same problem. If I write that in JS
I should expect the same thing as your asking, but I know that there is a
chance of that floating point rearing its ugly head.

 

And that Gareth is a fact of life as a program. Deal with it or move on,

 



Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613  8676 4223
Mobile: 0404 998 273

 

From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Gareth Edwards
Sent: Tuesday, 20 February 2007 2:14 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02

 

Who's missing my point? One shouldn't have to worry about typing in
Coldfusion. If in an evaluation a decimal is found amongst integers, it
should still calculate correctly. Whether it does this by making the other
values decimals, I don't care, but Coldfusion is a plain English language,
and it not typed, there for if one reads cfdump var=#1024-1024.1# as
-0.1 I think that is what coldfusion should return.

Cheers
Gareth.

Ryan Sabir wrote: 

Here's a technote from Sun, regarding Java.. the underlying subsystem of
ColdFusion:

 

http://java.sun.com/developer/JDCTechTips/2001/tt0807.html

 

I wouldn't expect this to be in the CF documentation. It's not Adobe's
problem.


  _  


From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Gareth Edwards
Sent: Tuesday, 20 February 2007 1:42 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02

Now you show me in the Coldfusion Documentation where this is outlined
as a known issue?

Cheers
Gareth.

Ryan Sabir wrote: 

 

Doesn't really matter why... Maybe there's a gremlin that lives in the last
0.00015 of every floating point number. Every now and then he will
wake up and mess up your number, and sometime's he'll stay asleep. Write
your code expecting he might pop round for a visit, and he won't bother you.

 

If you really want to find out why, then you'll need to do some pretty hard
core maths to work out how fractions are represented in binary. I prefer to
leave that to the geeks who work at Intel and AMD while I get on with my
work.


 


  _  


From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Gareth Edwards
Sent: Tuesday, 20 February 2007 1:11 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02

So why the mixed result?

Cheers
Gareth.

Ryan Sabir wrote: 

Just remembered I had a 6.1 server lying around. And yes it did the same
thing:

 

0.1
0.1
0.1
0.09985
0.09985
0.1
0.09985
0.1
0.1
0.09985
0.1
0.09985
0.09985
0.09985
0.1
0.1
0.1

 









 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





Indicating you know how Coldfusion works really proves nothing, I'm
quite aware of how it all works. I'm just annoyed that Coldfusion
doesn't deal with this situation better than it does.

Once again, _javascript_, although not strictly typed, is a typed
language. If I could type in Coldfusion I would.

Also, Coldfusion should get this one right, but it doesn't cfdump
var="#1024.00-1024.10#" returns -0.0

Cheers
Gareth.

Andrew Scott wrote:

  
  

  
  
  Gareth,
  
  I
think you are missing the point, whether coldfusion is a typed
language or not. The underlying technology of CF has a problem with
what your
asking.
  
  Now
just a fresher in how CF works for you, Coldfusion will
always try to treat everything as a numerical value first if this
throws an exception
it is then treated as a string. Now because CF has that, that doesnt
mean that
I see variable=1024-1024.1 and treat the example as you are asking why.
Because
of the problem that Ryan has stated to you, and it doesnt matter what
language
you are in, it will be the same problem. If I write that in JS I should
expect
the same thing as your asking, but I know that there is a chance of
that
floating point rearing its ugly head.
  
  And
that Gareth is a fact of life as a program. Deal with it or
move on,
  
  
  
Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
  www.aegeon.com.au
Phone:+613 8676 4223
  Mobile:
0404 998
273
  
  
  
  From:
cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On
Behalf Of Gareth
Edwards
  Sent: Tuesday, 20 February 2007 2:14 PM
  To: cfaussie@googlegroups.com
  Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02
  
  
  
  Who's missing my point? One shouldn't have to
worry about
typing in Coldfusion. If in an evaluation a decimal is found amongst
integers,
it should still calculate correctly. Whether it does this by making the
other
values decimals, I don't care, but Coldfusion is a plain English
language, and
it not typed, there for if one reads cfdump
var="#1024-1024.1#" as -0.1 I think that is what coldfusion
should return.
  
Cheers
Gareth.
  
Ryan Sabir wrote: 
  Here's
a technote
from Sun, regarding Java.. the underlying subsystem of ColdFusion:
  
  http://java.sun.com/developer/JDCTechTips/2001/tt0807.html
  
  I
wouldn't expect
this to be in the CF documentation. It's not Adobe's problem.
  


From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com]
On
Behalf Of Gareth Edwards
Sent: Tuesday, 20 February 2007 1:42 PM
To: cfaussie@googlegroups.com
    Subject: [cfaussie] Re: Strange calculation behavior on CF
7.02
Now you show me in the Coldfusion
Documentation where
this is outlined as a known issue?

Cheers
Gareth.

Ryan Sabir wrote: 

Doesn't
really
matter why... Maybe there's a gremlin that lives in the last
0.00015 of
every floating point number. Every now and then he will wake up and
mess up
your number, and sometime's he'll stay asleep. Write your code
expecting he
might pop round for a visit, and he won't bother you.

If
you really want
to find out why, then you'll need to do some pretty hard core maths to
work out
how fractions are represented in binary. I prefer to leave that to the
geeks
who work at Intel and AMD while I get on with my work.





  
  
  From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com]
  On
Behalf Of Gareth Edwards
  Sent: Tuesday, 20 February 2007 1:11 PM
  To: cfaussie@googlegroups.com
  Subject: [cfaussie] Re: Strange calculation behavior on CF
7.02
  So why the mixed result?
  
Cheers
Gareth.
  
Ryan Sabir wrote: 
  Just
remembered I
had a 6.1 server lying around. And yes it did the same thing:
  
  0.1
0.1
0.1
0.09985
0.09985
0.1
0.09985
0.1
0.1
0.09985
0.1
0.09985
0.09985
0.09985
0.1
0.1
0.1






  
  
  
  
  
  
  
  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Robin Hilliard

It's easier to see the pattern without the random stuff and the extra  
additions and subtractions, note val() etc have nothing to do with it:

cfloop from=1 to=1 index=a
 cfset c = a + 0.1
 cfset d = a - c
 cfoutput#a# - #c# = #d#br//cfoutput
/cfloop


1019 - 1019.1 = -0.1
1020 - 1020.1 = -0.1
1021 - 1021.1 = -0.1
1022 - 1022.1 = -0.1
1023 - 1023.1 = -0.1
1024 - 1024.1 = -0.0
1025 - 1025.1 = -0.0
1026 - 1026.1 = -0.0
1027 - 1027.1 = -0.0
1028 - 1028.1 = -0.0
...
4090 - 4090.1 = -0.0
4091 - 4091.1 = -0.0
4092 - 4092.1 = -0.0
4093 - 4093.1 = -0.0
4094 - 4094.1 = -0.0
4095 - 4095.1 = -0.0
4096 - 4096.1 = -0.1
4097 - 4097.1 = -0.1
4098 - 4098.1 = -0.1
4099 - 4099.1 = -0.1
4100 - 4100.1 = -0.1
4101 - 4101.1 = -0.1
4102 - 4102.1 = -0.1
4103 - 4103.1 = -0.1
4104 - 4104.1 = -0.1


I get errors for the range 1024 = a  4096.  Note 1024 = 2 ^ 10 and  
4096 = 2 ^ 12 - significant numbers in the binary world.

These sorts of errors are caused because you cannot represent all  
fractional amounts in a finite number of binary digits - for instance  
0.1 is an endlessly repeating 1100110011001100... pattern in binary  
(just like 1/3 is an endlessly repeating series in decimal). Replace  
0.1 in the above code with 0.125 (1/8) or another fraction that can  
be represented in a finite number of binary digits and you'll see the  
error disappears, or if you use 0.7 you'll see the error kick in at a  
 = 8192 (2 ^ 13).  Without further analysis, it's probably something  
to do with the way negative numbers (see two's complement) are  
represented in binary, and the point in the repeating sequence of  
binary digits where a Java floating point number runs out of precision.

As Ryan suggested, these rounding errors happen on any digital  
computer/language and your code needs to deal with them gracefully.

Cheers,
Robin

__

Robin Hilliard
Director - RocketBoots Pty Ltd
Consulting . Recruitment . Software Licensing . Training
http://www.rocketboots.com.au

For schedule/availability call Pamela Higgins:
w+61 7 5451 0362
m+61 419 677 151
f+61 3 9923 6261
e[EMAIL PROTECTED]

or Direct:
m+61 418 414 341
e[EMAIL PROTECTED]


On 20/02/2007, at 12:04 PM, Gareth Edwards wrote:


 If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

 Run this script below, and tell me if you get the same results for  
 each
 line. The way I see it, d should equal 0.1 on every row. But this  
 isn't
 the case. Is this a bug introduced by Coldfusion 7.02?

 cfset a = 0
 cfset b = 0
 cfset c = 0

 cfloop from=1 to=1000 index=i
 cfset a = RandRange(1,2)
 cfset b = a*2
 cfset c = #ListFirst(Trim(a),.)#.00
 cfset c = c + 0.1
 cfset d = a - val(b) + val(c)
 cfoutput#d#br //cfoutput
 /cfloop

 Cheers
 Gareth.

 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Gareth Edwards





Sorry to complain about it, it just seems strange, I won't complain
anymore. Does it do the same thing in Actionscript? (don't have time to
check right now)

What do you think is the best way to handle this in coldfusion?

Also, I'm curious, how many people on this list are aware of this issue?

Cheers
Gareth.

Robin Hilliard wrote:

  It's easier to see the pattern without the random stuff and the extra  
additions and subtractions, note val() etc have nothing to do with it:

cfloop from="1" to="1" index="a"
 cfset c = a + 0.1
 cfset d = a - c
 cfoutput#a# - #c# = #d#br//cfoutput
/cfloop


1019 - 1019.1 = -0.1
1020 - 1020.1 = -0.1
1021 - 1021.1 = -0.1
1022 - 1022.1 = -0.1
1023 - 1023.1 = -0.1
1024 - 1024.1 = -0.0
1025 - 1025.1 = -0.0
1026 - 1026.1 = -0.0
1027 - 1027.1 = -0.0
1028 - 1028.1 = -0.0
...
4090 - 4090.1 = -0.0
4091 - 4091.1 = -0.0
4092 - 4092.1 = -0.0
4093 - 4093.1 = -0.0
4094 - 4094.1 = -0.0
4095 - 4095.1 = -0.0
4096 - 4096.1 = -0.1
4097 - 4097.1 = -0.1
4098 - 4098.1 = -0.1
4099 - 4099.1 = -0.1
4100 - 4100.1 = -0.1
4101 - 4101.1 = -0.1
4102 - 4102.1 = -0.1
4103 - 4103.1 = -0.1
4104 - 4104.1 = -0.1


I get errors for the range 1024 = a  4096.  Note 1024 = 2 ^ 10 and  
4096 = 2 ^ 12 - significant numbers in the binary world.

These sorts of errors are caused because you cannot represent all  
fractional amounts in a finite number of binary digits - for instance  
0.1 is an endlessly repeating 1100110011001100... pattern in binary  
(just like 1/3 is an endlessly repeating series in decimal). Replace  
0.1 in the above code with 0.125 (1/8) or another fraction that can  
be represented in a finite number of binary digits and you'll see the  
error disappears, or if you use 0.7 you'll see the error kick in at a  
 = 8192 (2 ^ 13).  Without further analysis, it's probably something  
to do with the way negative numbers (see "two's complement") are  
represented in binary, and the point in the repeating sequence of  
binary digits where a Java floating point number runs out of precision.

As Ryan suggested, these rounding errors happen on any digital  
computer/language and your code needs to deal with them gracefully.

Cheers,
Robin

__

Robin Hilliard
Director - RocketBoots Pty Ltd
Consulting . Recruitment . Software Licensing . Training
http://www.rocketboots.com.au

For schedule/availability call Pamela Higgins:
w+61 7 5451 0362
m+61 419 677 151
f+61 3 9923 6261
e[EMAIL PROTECTED]

or Direct:
m+61 418 414 341
e[EMAIL PROTECTED]


On 20/02/2007, at 12:04 PM, Gareth Edwards wrote:

  
  
If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

Run this script below, and tell me if you get the same results for  
each
line. The way I see it, d should equal 0.1 on every row. But this  
isn't
the case. Is this a bug introduced by Coldfusion 7.02?

cfset a = 0
cfset b = 0
cfset c = 0

cfloop from="1" to="1000" index="i"
cfset a = RandRange(1,2)
cfset b = a*2
cfset c = "#ListFirst(Trim(a),".")#.00"
cfset c = c + 0.1
cfset d = a - val(b) + val(c)
cfoutput#d#br //cfoutput
/cfloop

Cheers
Gareth.



  
  


  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups cfaussie group.  To post to this group, send email to cfaussie@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en  -~--~~~~--~~--~--~---





[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Barry Beattie

to part answer that, what were you doing to bring this matter to your attention?



On 2/20/07, Gareth Edwards [EMAIL PROTECTED] wrote:

  Sorry to complain about it, it just seems strange, I won't complain
 anymore. Does it do the same thing in Actionscript? (don't have time to
 check right now)

  What do you think is the best way to handle this in coldfusion?

  Also, I'm curious, how many people on this list are aware of this issue?

  Cheers
  Gareth.


  Robin Hilliard wrote:
  It's easier to see the pattern without the random stuff and the extra
 additions and subtractions, note val() etc have nothing to do with it:

 cfloop from=1 to=1 index=a
  cfset c = a + 0.1
  cfset d = a - c
  cfoutput#a# - #c# = #d#br//cfoutput
 /cfloop


 1019 - 1019.1 = -0.1
 1020 - 1020.1 = -0.1
 1021 - 1021.1 = -0.1
 1022 - 1022.1 = -0.1
 1023 - 1023.1 = -0.1
 1024 - 1024.1 = -0.0
 1025 - 1025.1 = -0.0
 1026 - 1026.1 = -0.0
 1027 - 1027.1 = -0.0
 1028 - 1028.1 = -0.0
 ...
 4090 - 4090.1 = -0.0
 4091 - 4091.1 = -0.0
 4092 - 4092.1 = -0.0
 4093 - 4093.1 = -0.0
 4094 - 4094.1 = -0.0
 4095 - 4095.1 = -0.0
 4096 - 4096.1 = -0.1
 4097 - 4097.1 = -0.1
 4098 - 4098.1 = -0.1
 4099 - 4099.1 = -0.1
 4100 - 4100.1 = -0.1
 4101 - 4101.1 = -0.1
 4102 - 4102.1 = -0.1
 4103 - 4103.1 = -0.1
 4104 - 4104.1 = -0.1


 I get errors for the range 1024 = a  4096. Note 1024 = 2 ^ 10 and
 4096 = 2 ^ 12 - significant numbers in the binary world.

 These sorts of errors are caused because you cannot represent all
 fractional amounts in a finite number of binary digits - for instance
 0.1 is an endlessly repeating 1100110011001100... pattern in binary
 (just like 1/3 is an endlessly repeating series in decimal). Replace
 0.1 in the above code with 0.125 (1/8) or another fraction that can
 be represented in a finite number of binary digits and you'll see the
 error disappears, or if you use 0.7 you'll see the error kick in at a
  = 8192 (2 ^ 13). Without further analysis, it's probably something
 to do with the way negative numbers (see two's complement) are
 represented in binary, and the point in the repeating sequence of
 binary digits where a Java floating point number runs out of precision.

 As Ryan suggested, these rounding errors happen on any digital
 computer/language and your code needs to deal with them gracefully.

 Cheers,
 Robin

 __

 Robin Hilliard
 Director - RocketBoots Pty Ltd
 Consulting . Recruitment . Software Licensing . Training
 http://www.rocketboots.com.au

 For schedule/availability call Pamela Higgins:
 w +61 7 5451 0362
 m +61 419 677 151
 f +61 3 9923 6261
 e [EMAIL PROTECTED]

 or Direct:
 m +61 418 414 341
 e [EMAIL PROTECTED]


 On 20/02/2007, at 12:04 PM, Gareth Edwards wrote:



  If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

 Run this script below, and tell me if you get the same results for
 each
 line. The way I see it, d should equal 0.1 on every row. But this
 isn't
 the case. Is this a bug introduced by Coldfusion 7.02?

 cfset a = 0
 cfset b = 0
 cfset c = 0

 cfloop from=1 to=1000 index=i
  cfset a = RandRange(1,2)
  cfset b = a*2
  cfset c = #ListFirst(Trim(a),.)#.00
  cfset c = c + 0.1
  cfset d = a - val(b) + val(c)
  cfoutput#d#br //cfoutput
 /cfloop

 Cheers
 Gareth.








  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread skateboard.com.au

Our teacher gave us the low down on this issue in the first week of my C 
unit. You probably dont hear about it too much in CF land as its so 
losely typed.  

cheers

Drew Peacock


-Original Message-
From: Gareth Edwards [EMAIL PROTECTED]
To: cfaussie@googlegroups.com
Date: Tue, 20 Feb 2007 14:27:34 +1000
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02

 
 !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
 html
 head
   meta content=text/html;charset=ISO-8859-1
 http-equiv=Content-Type
 /head
 body bgcolor=#ff text=#00
 Sorry to complain about it, it just seems strange, I won't complain
 anymore. Does it do the same thing in Actionscript? (don't have time to
 check right now)br
 br
 What do you think is the best way to handle this in coldfusion?br
 br
 Also, I'm curious, how many people on this list are aware of this
 issue?br
 br
 Cheersbr
 Gareth.br
 br
 Robin Hilliard wrote:
 blockquote
  cite=mid:[EMAIL PROTECTED]
  type=cite
   pre wrap=It's easier to see the pattern without the random stuff
 and the extra  
 additions and subtractions, note val() etc have nothing to do with it:
 
 lt;cfloop from=1 to=1 index=agt;
  lt;cfset c = a + 0.1gt;
  lt;cfset d = a - cgt;
  lt;cfoutputgt;#a# - #c# = #d#lt;br/gt;lt;/cfoutputgt;
 lt;/cfloopgt;
 
 
 1019 - 1019.1 = -0.1
 1020 - 1020.1 = -0.1
 1021 - 1021.1 = -0.1
 1022 - 1022.1 = -0.1
 1023 - 1023.1 = -0.1
 1024 - 1024.1 = -0.0
 1025 - 1025.1 = -0.0
 1026 - 1026.1 = -0.0
 1027 - 1027.1 = -0.0
 1028 - 1028.1 = -0.0
 ...
 4090 - 4090.1 = -0.0
 4091 - 4091.1 = -0.0
 4092 - 4092.1 = -0.0
 4093 - 4093.1 = -0.0
 4094 - 4094.1 = -0.0
 4095 - 4095.1 = -0.0
 4096 - 4096.1 = -0.1
 4097 - 4097.1 = -0.1
 4098 - 4098.1 = -0.1
 4099 - 4099.1 = -0.1
 4100 - 4100.1 = -0.1
 4101 - 4101.1 = -0.1
 4102 - 4102.1 = -0.1
 4103 - 4103.1 = -0.1
 4104 - 4104.1 = -0.1
 
 
 I get errors for the range 1024 lt;= a lt; 4096.  Note 1024 = 2 ^ 10
 and  
 4096 = 2 ^ 12 - significant numbers in the binary world.
 
 These sorts of errors are caused because you cannot represent all  
 fractional amounts in a finite number of binary digits - for instance  
 0.1 is an endlessly repeating 1100110011001100... pattern in binary  
 (just like 1/3 is an endlessly repeating series in decimal). Replace  
 0.1 in the above code with 0.125 (1/8) or another fraction that can  
 be represented in a finite number of binary digits and you'll see the  
 error disappears, or if you use 0.7 you'll see the error kick in at a  
  gt;= 8192 (2 ^ 13).  Without further analysis, it's probably
 something  
 to do with the way negative numbers (see two's complement) are  
 represented in binary, and the point in the repeating sequence of  
 binary digits where a Java floating point number runs out of precision.
 
 As Ryan suggested, these rounding errors happen on any digital  
 computer/language and your code needs to deal with them gracefully.
 
 Cheers,
 Robin
 
 __
 
 Robin Hilliard
 Director - RocketBoots Pty Ltd
 Consulting . Recruitment . Software Licensing . Training
 a class=moz-txt-link-freetext
 href=http://www.rocketboots.com.au;http://www.rocketboots.com.au/a
 
 For schedule/availability call Pamela Higgins:
 w+61 7 5451 0362
 m+61 419 677 151
 f+61 3 9923 6261
 ea class=moz-txt-link-abbreviated
 href=mailto:[EMAIL PROTECTED][EMAIL PROTECTED]/a
 
 or Direct:
 m+61 418 414 341
 ea class=moz-txt-link-abbreviated
 href=mailto:[EMAIL PROTECTED][EMAIL PROTECTED]/a
 
 
 On 20/02/2007, at 12:04 PM, Gareth Edwards wrote:
 
   /pre
   blockquote type=cite
 pre wrap=If you are running coldfusion 7.02, or maybe 7.01 or
 7.0? (don't know)
 
 Run this script below, and tell me if you get the same results for  
 each
 line. The way I see it, d should equal 0.1 on every row. But this  
 isn't
 the case. Is this a bug introduced by Coldfusion 7.02?
 
 lt;cfset a = 0gt;
 lt;cfset b = 0gt;
 lt;cfset c = 0gt;
 
 lt;cfloop from=1 to=1000 index=igt;
 lt;cfset a = RandRange(1,2)gt;
 lt;cfset b = a*2gt;
 lt;cfset c = #ListFirst(Trim(a),.)#.00gt;
 lt;cfset c = c + 0.1gt;
 lt;cfset d = a - val(b) + val(c)gt;
 lt;cfoutputgt;#d#lt;br /gt;lt;/cfoutputgt;
 lt;/cfloopgt;
 
 Cheers
 Gareth.
 
 
 /pre
   /blockquote
   pre wrap=!
 
 
   /pre
 /blockquote
 br
 br
  /body
 /html
 br



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Andrew Scott
Restrict the decimal paces and force a round off!

 



Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613  8676 4223
Mobile: 0404 998 273

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread Steve Onnis
Do you get the same issue with punch cards?  Maybe that's an option:P

 

What is it your trying to do in the first place? Or were you just having an
I wonder what would happen if... moment?

 

Steve

 

  _  

From: cfaussie@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of Robin Hilliard
Sent: Tuesday, 20 February 2007 3:54 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] Re: Strange calculation behavior on CF 7.02

 

On 20/02/2007, at 3:27 PM, Gareth Edwards wrote:

 

Sorry to complain about it,

 

Don't worry, you were somewhat provoked over the course of the thread (I
would recommend the more frequent posters on cfaussie buy a copy of Parent
Effectiveness Training by Dr. Thomas R. Gordon ISBN 0609806939 to find out
how to peacefully turn a confrontation into a win/win situation for
everyone), the original question was fair enough :)





it just seems strange, I won't complain anymore. Does it do the same thing
in Actionscript? (don't have time to check right now)

 

It should.





What do you think is the best way to handle this in coldfusion?

 

If you only wanted to nearest 0.1 you could say:

 

nice = round(possiblyyuck * 10) / 10





Also, I'm curious, how many people on this list are aware of this issue?

 

Developers doing floating point calculations in any programming language
comes across it sooner or later - on a digital computer*.

 

Cheers,

Robin

 

 

 

* The only mechanical computer I've seen (not working) that wouldn't run
into this is the _analog_ computer that used to be in the basement of the
computer science faculty at Sydney Uni, preserved by the late Prof. Alan
Bromley.  This was the sort of thing they used for the Apollo program - it
looked like a big grey tote board - you'd actually wire up a differential
equation with patch leads, set the inputs using dials, the current would
flow and you'd read the results from an oscilloscope. 

 

 





 

__

 

Robin Hilliard

Director - RocketBoots Pty Ltd

Consulting . Recruitment . Software Licensing . Training

http://www.rocketboots.com.au

 

For schedule/availability call Pamela Higgins:

w+61 7 5451 0362

m+61 419 677 151

f+61 3 9923 6261

e[EMAIL PROTECTED]

 

or Direct:

m+61 418 414 341

e[EMAIL PROTECTED]





 





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---



[cfaussie] Re: Strange calculation behavior on CF 7.02

2007-02-19 Thread rod higgins

If you use the java class and methods that handle these types of
numbers I don't see the problem??

cfloop from=1 to=1000 index=i
cfset diff = CreateObject(Java, java.math.BigDecimal).init(0.1)
cfset a = CreateObject(Java,
java.math.BigDecimal).init(RandRange(100,1))
cfset b = CreateObject(Java,
java.math.BigDecimal).init(a*2)
cfset c = CreateObject(Java,
java.math.BigDecimal).init(val(a))
cfset c = c.add(diff)
cfset d = a.subtract(b).add(c)
cfoutput#a#-#b#+#c# = #d#br //cfoutput
/cfloop

It seems CF is using some sort of toString() value during the
calculation at some stage??

hth
Rod

On Feb 20, 12:04 pm, Gareth Edwards [EMAIL PROTECTED] wrote:
 If you are running coldfusion 7.02, or maybe 7.01 or 7.0? (don't know)

 Run this script below, and tell me if you get the same results for each
 line. The way I see it, d should equal 0.1 on every row. But this isn't
 the case. Is this a bug introduced by Coldfusion 7.02?

 cfset a = 0
 cfset b = 0
 cfset c = 0

 cfloop from=1 to=1000 index=i
 cfset a = RandRange(1,2)
 cfset b = a*2
 cfset c = #ListFirst(Trim(a),.)#.00
 cfset c = c + 0.1
 cfset d = a - val(b) + val(c)
 cfoutput#d#br //cfoutput
 /cfloop

 Cheers
 Gareth.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
cfaussie group.
To post to this group, send email to cfaussie@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en
-~--~~~~--~~--~--~---