Wrong calculation with single vs. double

hello

is this a bug or do i misunderstand the range of single type?

i have the number value 0.7531 in a numeric field

when i move this value in a single array (Dim xchange(0 To 1) As Single) and then move this value in a multivalue numeric field i get the value 0.753099977970123

on operating this with double type i get the correct 0.7531

single should be in the range -3.402823E+38 to 3.402823E+38 according to help and therefore the behaviour above should not appear

so the single type is (for me) totally useless, or not?

greets

ingo

Subject: wrong calculation with single vs. double

It’s not the range, it’s the accuracy, or the number of bits used to represent the mantissa. There is always going to be some degree of error representing decimal fractions as binary numbers, since only those numbers that can be expressed exactly as a power of 2 have exact equivalents. A single doesn’t have enough bits available to reduce the error to less than the Notes client can display. One thing to keep in mind, though, is that even if the client is displaying 0.7531, the actual value stored may well be 0.7530999999999999999999999993 or some such. It’s not a problem unique to Notes or LotusScript – all floating point operations behave that way unless the system is using BCD (binary-coded decimal).

Subject: RE: wrong calculation with single vs. double

thank you stan for your answer

but for what is the single type then existing?

in debugger the single parameter had the correct value

but in the moment of writing the number in the notes field then the accuracy failed, this is weird resp. the debugger shows rounded values, even bad

greets

ingo

Subject: RE: wrong calculation with single vs. double

The Single is there to limit the amount of memory a program uses. Programming is always a trade-off, and which data type you choose to use for a particular value depends on what is more important to your program.