![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've got an array of values. When I sum by referencing array entries, I get on thing but if I sum the values, I get another thing. It's got to be something around the use of Variant instead of Double, but I can't figure out what. e.g. ---------------------------------------------------------------- Return Stream (Date:Rate) 3/1/2010:0.0293, 6/1/2010:0.02674, 9/1/2010:0.0408, 12/1/2010:-0.04 Public Type ReturnInfo ReturnDate As Variant ReturnRate As Variant End Type Dim myRI() As ReturnInfo ==> (Load stream into myRI and add 1 to each rate) <== Immediate Window: ---------------- ?myRI(0).ReturnRate 1.0293 ?myRI(1).ReturnRate 1.02674 ?myRI(2).ReturnRate 1.0408 ?myRI(3).ReturnRate 0.96 ?myRI(0).ReturnRate * myRI(1).ReturnRate * myRI(2).ReturnRate * myRI(3).ReturnRate 1.05594420486298 ?1.0293 * 1.2674 * 1.02674 * 1.0408 * .96 1.33830368524334 ---------------------------------------------------------------- Note the diff: 1.055 vs 1.338. Can anybody explain? This code was written 7 years ago, and I'm assuming there is a reason for the use of Variant instead of Double. If that use explains the problem, I'll change it and start regression testing.... but a full regression test is going to take a loooooong time and I want to make sure I understand the implications first. |
#3
| |||
| |||
|
|
The line that is giving you fits is the second. it should be 1.0293 * 1.02674 * 1.0408 * 0.96 You had 1.2674, not 1.02674 |
#4
| |||
| |||
|
|
Per Salad: The line that is giving you fits is the second. it should be 1.0293 * 1.02674 * 1.0408 * 0.96 You had 1.2674, not 1.02674 Aw geeze...... -) I should have gone back to Occam's Razor - where the simplest explanation is RCI. "Sometimes you kill the dragon... sometimes the dragon kills you..." |
#5
| |||
| |||
|
|
and you're going to introduce floating point inaccuracies. |
#6
| |||
| |||
|
|
Per David-W-Fenton: and you're going to introduce floating point inaccuracies. Which begs a question: should one even use Double fields unless they are absolutely necessary? Late in the game it dawned on me that, if the user could make do with no more than 4 decimal places, the "Currency" data type would be used for something non-currency-related like shares of stock. I've got one application where, every so often, a query against shares that actually net out to zero, will return something like .000000045644 instead of zero. Part of me says "bite the bullet and convert". The other part fears unintended consequences. |
#7
| |||
| |||
|
|
Which begs a question: should one even use Double fields unless they are absolutely necessary? Late in the game it dawned on me that, if the user could make do with no more than 4 decimal places, the "Currency" data type would be used for something non-currency-related like shares of stock. I've got one application where, every so often, a query against shares that actually net out to zero, will return something like .000000045644 instead of zero. Part of me says "bite the bullet and convert". * The other part fears unintended consequences. -- PeteCresswell |
![]() |
| Thread Tools | |
| Display Modes | |
| |