## User Tag List

My £2 desk calculator can work this one
out correctly.

;try this
result = (1 - 1.01)

msgbox("(1 - 1.01)", result)

But apparently QARun can't.

------------------

2. ## Re: Advanced Mathmatical Functions

My £2 desk calculator can work this one
out correctly.
;try this
result = (1 - 1.01)

msgbox("(1 - 1.01)", result)

But apparently QARun can't.

Hello,
When i try this I get the result -1.e-002
which is -1 x 10e-2 then -0.01 so for me, it works.

What do you get?

------------------

3. ## Re: Advanced Mathmatical Functions

I know but when your trying to compare numeric strings -1.e-002 and -0.01 are about
as far apart as you can get.

------------------

4. ## Re: Advanced Mathmatical Functions

<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by sreilly:
I know but when your trying to compare numeric strings -1.e-002 and -0.01 are about
as far apart as you can get.

<HR></BLOCKQUOTE>

Hi sreilly!
Sorry to disappoint you, but those results are the same!
The -1.e-002 is a scientific notation, which stands for "minus 1 times 10 to the power of -2", so this is equivalent to -0.01.
You're correct in being surprised by QARun using this scientific notation, as I was this morning after
[q]
Var a = 0.01
MsgBox("a", a)
[/q]
and seeing 1.e-002 displayed...
It would be nice to have some kind of display control (yep, like you have in your £2 desk calculator ).

Leo (who also is a mathematician, btw)

------------------

5. ## Re: Advanced Mathmatical Functions

The format was my point exactly, i had timers running to see how long it took screens to appear, the results of
which were written back to a text file so they could be compared against the next test run.

When it came to compare the results mentioned above the compare would always fail.

I'm aware the numbers are numberically the same but try:

num1 = -0.01
num2 = (1 - 1.01)

; this message box displays -1.e-002 for both numbers
msgbox(num1, num2)

;but

If num1 = num2

msgbox("They Match","")

Else

Msgbox("No Match","")

Endif

And qarun will tell you there different.
But if you specifically tell QARun that
num1 = -0.01
num2 = -1.e-002

Then it'll confirm they match, but if one
of the two num's if the result of a calculation then it can't match them.

Not ideal when your comparing times.

------------------

6. ## Re: Advanced Mathmatical Functions

<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by sreilly:
The format was my point exactly, i had timers running to see how long it took screens to appear, the results of
which were written back to a text file so they could be compared against the next test run.

When it came to compare the results mentioned above the compare would always fail.

I'm aware the numbers are numberically the same but try:

num1 = -0.01
num2 = (1 - 1.01)

; this message box displays -1.e-002 for both numbers
msgbox(num1, num2)

;but

If num1 = num2

msgbox("They Match","")

Else

Msgbox("No Match","")

Endif

And qarun will tell you there different.
But if you specifically tell QARun that
num1 = -0.01
num2 = -1.e-002

Then it'll confirm they match, but if one
of the two num's if the result of a calculation then it can't match them.

Not ideal when your comparing times.

<HR></BLOCKQUOTE>

Hi again, sreilly!
Never forget when comparing numbers that you allow for a small difference.
Note that you cannot represent most numbers correctly (this becomes clear fast if you known that there are a finite number of internal representation, and an infinite number of different numbers).
For instance, try to represent 1/3 decimally.
0.3333333333333333333333333333 is a nice try, but not correct.
Write it as
If Abs(num1, num2) &lt; 1.e-008
msgbox("They Match","")
Else
Msgbox("No Match","")
Endif
If you're not comfortable with this construct, make it into a two parameter function you can use to compare two numbers.
Let it for instance return 0 if they're close enough (c.f. the QARun compare() function for strings).

Leo

------------------

7. ## Re: Advanced Mathmatical Functions

Hi Leo,

Seems like a lot of grief just to find out how much faster/slower a screen appeared on a new build doesn't it

------------------

[This message has been edited by sreilly (edited 02-13-2003).]

8. ## Re: Advanced Mathmatical Functions

<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by sreilly:
Hi Leo,

Seems like a lot of grief just to find out how much faster/slower a screen appeared on a new build doesn't it

<HR></BLOCKQUOTE>
Hi sreilly!
Sure, but look on the bright side: you learned how to compare numbers digitally.
(and a pity it's usually underestimated).
About 30 years ago I learned about it on a course of numerical mathematics.

Leo

------------------

9. ## Re: Advanced Mathmatical Functions

Hello ;
Yesterady I have similar case ;
I have tree numbers :

s = 50.05
t = 10.01
y = 60.06

;difference :
r = s + t - y
msgbox ("r=",r)

expected result : r = 0
received result : r = -7.105427357601e-015

------------------

10. ## Re: Advanced Mathmatical Functions

Hi Witold

Short study...
This is becouse a variable float type.
I'll try to explain the problem by analogy to C (included in this small piece of code). Float number is stored in memory as normalized value and is expressed as +/-(1+M)*2^E; where Mantisa is 0&lt;=M&lt;1 and must be representable in binary using 24 digits (for 4 byte floats).
All 32 bits you have got in memory are represented by SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM
where S is sign of number, 8E is exponent and 23M is mantisa. Becouse of normalization 24-th bit (rather 0) of M is set to 1 and it's not stored in memory, instead you have sign of number. (important: 8E is like C signed char, it means that your exponent is between -127 and 128).
Let's have an example for 0.1f
SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM
00111101110011001100110011001101
computing E and exponent sign:
(B)01111011 == (DEC)123 - 127 == -4
computing M:
1st bit 23-th bit
| |
10011001100110011001101
and bit #0 - that is 1
all you have is
110011001100110011001101 (take all 1's)
2^-(0+4) + 2^-(1+4) + 2^-(4+4) + 2^-9....
Now you see that in binary system 1/10 is
computed as 1/16 + 1/32 + 1/128 + 1/256 + ... + 1/2^27
As you see it's impossible to have exactly .1 in float (double, etc...)
I should mention about float operations (but
loosing of associativity easy to imagine ;-)
If your number coud be represent as "2^n" (or its computation) you don't find this problem in your code.
Solution...
The simplest way to avoid that problem in QARun, is set precision of computed result or write a DLL (for example with use of curency type)

best regards

[This message has been edited by s2mich (edited 02-17-2003).]

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.