Click here to Skip to main content
15,896,727 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to create Digital Sign For My Application Pin
Anubhava Dimri3-Jun-09 22:17
Anubhava Dimri3-Jun-09 22:17 
QuestionVB 6.0 Language while Interpreting [modified] Pin
vhassan2-Jun-09 20:37
vhassan2-Jun-09 20:37 
Questionhow do i see/change the events of a form? Pin
neodeaths2-Jun-09 19:54
neodeaths2-Jun-09 19:54 
AnswerRe: how do i see/change the events of a form? Pin
Dave Kreskowiak3-Jun-09 2:02
mveDave Kreskowiak3-Jun-09 2:02 
GeneralRe: how do i see/change the events of a form? Pin
neodeaths4-Jun-09 5:58
neodeaths4-Jun-09 5:58 
GeneralRe: how do i see/change the events of a form? Pin
Dave Kreskowiak4-Jun-09 12:52
mveDave Kreskowiak4-Jun-09 12:52 
QuestionProblem when subtracting large double values [VB6.0] Pin
N a v a n e e t h2-Jun-09 15:48
N a v a n e e t h2-Jun-09 15:48 
AnswerRe: Problem when subtracting large double values [VB6.0] PinPopular
Luc Pattyn2-Jun-09 16:19
sitebuilderLuc Pattyn2-Jun-09 16:19 
Hi,

there most likely is nothing wrong. Have a look here[^].

It is inherent to floating-point numbers: they trade some accuracy for a much larger range.
A floating-point number stores a mantissa, an exponent and a sign.
the exponent indicates a power of 2, not 10, and uses anywhere between 8 and 16 bits.
the mantissa indicates a magnitude in a limited range, say in [0.5, 1) and uses some 23 to 50 bits
(details vary from one CPU family to the next, IEEE did some standardization attempts, not relevant here).

You have chosen to show the number as d = 2.3434543434E+15, now why didn't you chose d = 2.343454343411111111111E+15? I added some ones to emphasize that you stopped the representation hoping the decimal digits shown, exactly correspond to the binary bits present in the mantissa, which will not be true in general.

So one number could be 2.343454343411116E+15 whereas the other could be 2.343454343411114E+15 (I truncated where the decimal point would be when looking at integer values). So now the difference is exactly 2, whereas the quotient is 1 + epsilon, epsilon being a very small number (around 1/1.17E15);
a double would be able to hold epsilon very accurately, however 1+epsilon would not be discernible from 1.

It is a well known fact in numeric analysis subtracting two large and similar numbers increases the relative errors. Example: if you want to measure the thickness of a wall, you could measure the wall-to-wall distance of a room on the inside, do the same on the outside, and subtract. If you make a 1% error on those dimensions, your calculated wall thickness could be off by 10% or more.

If you want to see the details, try to have a look at the bit patterns used by d1 and d2; in .NET BitConverter.GetBytes() would give you access to them, I don't recall if and how it could be done in ancient VB.

A much simpler example illustrating the same principles would be to calculate 1/3 or 1/7, then multiplying again by 3 or 7; the result will not always be 1!

PS: the above is true in many/all programming languages; some do offer extra data types (such as decimal) to get yet another trade of of accuracy and range.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

GeneralRe: Problem when subtracting large double values [VB6.0] Pin
_Damian S_2-Jun-09 16:51
professional_Damian S_2-Jun-09 16:51 
GeneralRe: Problem when subtracting large double values [VB6.0] Pin
Jon_Boy3-Jun-09 1:59
Jon_Boy3-Jun-09 1:59 
GeneralRe: Problem when subtracting large double values [VB6.0] Pin
Luc Pattyn3-Jun-09 3:13
sitebuilderLuc Pattyn3-Jun-09 3:13 
GeneralRe: Problem when subtracting large double values [VB6.0] Pin
N a v a n e e t h2-Jun-09 16:57
N a v a n e e t h2-Jun-09 16:57 
GeneralRe: Problem when subtracting large double values [VB6.0] Pin
Luc Pattyn2-Jun-09 17:08
sitebuilderLuc Pattyn2-Jun-09 17:08 
GeneralRe: Problem when subtracting large double values [VB6.0] Pin
N a v a n e e t h2-Jun-09 17:22
N a v a n e e t h2-Jun-09 17:22 
GeneralRe: Problem when subtracting large double values [VB6.0] Pin
Luc Pattyn2-Jun-09 17:34
sitebuilderLuc Pattyn2-Jun-09 17:34 
Questiontruncate table in sql 2005 by vb,net code Pin
atk88772-Jun-09 12:14
atk88772-Jun-09 12:14 
AnswerRe: truncate table in sql 2005 by vb,net code Pin
Henry Minute2-Jun-09 12:35
Henry Minute2-Jun-09 12:35 
GeneralRe: truncate table in sql 2005 by vb,net code Pin
atk88773-Jun-09 12:06
atk88773-Jun-09 12:06 
GeneralRe: truncate table in sql 2005 by vb,net code Pin
Henry Minute3-Jun-09 12:45
Henry Minute3-Jun-09 12:45 
GeneralRe: truncate table in sql 2005 by vb,net code Pin
atk88774-Jun-09 1:32
atk88774-Jun-09 1:32 
QuestionExport Excel Formula Pin
ross16642-Jun-09 5:51
ross16642-Jun-09 5:51 
AnswerRe: Export Excel Formula Pin
Kschuler2-Jun-09 5:59
Kschuler2-Jun-09 5:59 
GeneralRe: Export Excel Formula Pin
ross16642-Jun-09 19:18
ross16642-Jun-09 19:18 
QuestionVB.net: How to update database from datagridview Pin
Roger Rainey2-Jun-09 4:35
Roger Rainey2-Jun-09 4:35 
AnswerRe: VB.net: How to update database from datagridview Pin
Kschuler2-Jun-09 5:45
Kschuler2-Jun-09 5:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.