Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Adron on December 15, 2005, 01:23 PM

Title: Math
Post by: Adron on December 15, 2005, 01:23 PM
Calculate 8000 * 0.3 - 8000 * 3 / 10

Comments?
Title: Re: Math
Post by: Explicit on December 15, 2005, 02:11 PM
0?
Title: Re: Math
Post by: Adron on December 15, 2005, 02:45 PM
Quote from: Explicit[nK] on December 15, 2005, 02:11 PM
0?

What version of VB did you use to come to that conclusion? If you did not, consider why this was posted to the VB forum... ;)
Title: Re: Math
Post by: Warrior on December 15, 2005, 02:55 PM
I got 0 (VB6)
Title: Re: Math
Post by: QwertyMonster on December 15, 2005, 02:55 PM
I got 0 too (I used Visual basic 6).
Title: Re: Math
Post by: Explicit on December 15, 2005, 02:57 PM
Quote from: Adron on December 15, 2005, 02:45 PM
Quote from: Explicit[nK] on December 15, 2005, 02:11 PM
0?

What version of VB did you use to come to that conclusion? If you did not, consider why this was posted to the VB forum... ;)

Pffffft, who needs VB when you have your fingers?  I counted out to 8000, and chopped off a finger to attain the three-tenths fraction, then smashed my hands together and found nothing was left. :)
Title: Re: Math
Post by: Adron on December 15, 2005, 04:09 PM
Hmm, weird. I did that in VB6, and did not get 0. Just typed it in the debug window,


?8000 * 0.3 - 8000 * 3 / 10
Title: Re: Math
Post by: Ringo on December 15, 2005, 04:45 PM
I got -8.88178419700125E-14
[Edit]: and -1500 in a string
Title: Re: Math
Post by: MyndFyre on December 15, 2005, 04:46 PM
Quote from: Adron on December 15, 2005, 04:09 PM
Hmm, weird. I did that in VB6, and did not get 0. Just typed it in the debug window,


?8000 * 0.3 - 8000 * 3 / 10


Perhaps the debug window doesn't follow order of operations?
Title: Re: Math
Post by: Hdx on December 15, 2005, 06:25 PM
Wow another reason ive droped VB.
But one question. WTF!?!?!
~-~(HDX)~-~
Title: Re: Math
Post by: Adron on December 15, 2005, 06:37 PM
Quote from: MyndFyre on December 15, 2005, 04:46 PM
Perhaps the debug window doesn't follow order of operations?

Well, it originally came from a larger program. So it's not just the debug window.
Title: Re: Math
Post by: l)ragon on December 15, 2005, 10:35 PM
Quote from: Adron on December 15, 2005, 01:23 PM
Calculate 8000 * 0.3 - 8000 * 3 / 10

Comments?
'VB6
Private Sub Form_Load()
Dim a As Double
Dim b As Double
Dim x As Double
Dim y As Double
    a = 8000 * 0.3     '2400
    b = 8000 * 3 / 10  '2400
    x = a - b
    y = 8000 * 0.3 - 8000 * 3 / 10
Debug.Print x 'Real answer
'= 0
Debug.Print y 'Real Problem
'= -8.88178419700125E-14
End Sub

Is this problem only with subtraction? (Addition works fine.)

I guess the solution to this is to create your own calculation processor.
Title: Re: Math
Post by: Ringo on December 15, 2005, 11:10 PM
Currency can do it all in one:
Const Zero As Currency = 8000 * 0.3 - 8000 * 3 / 10
Title: Re: Math
Post by: Adron on December 16, 2005, 12:00 AM
Quote from: Ringo on December 15, 2005, 11:10 PM
Currency can do it all in one:
Const Zero As Currency = 8000 * 0.3 - 8000 * 3 / 10

Currency can't handle the size of the answer so it rounds to zero. I'll give you another test for that though:

Const Answer As Currency = Fix(8000 * 0.3)
Title: Re: Math
Post by: Ringo on December 16, 2005, 03:28 AM
hmm, what about CDec(CDbl(8000 * 0.3) - CDbl(8000 * 3 / 10))?
Title: Re: Math
Post by: MyndFyre on December 16, 2005, 09:59 AM
You don't suppose VB uses its own floating-point library from the days that most computers didn't have coprocessors, do you?
Title: Re: Math
Post by: l2k-Shadow on December 17, 2005, 07:18 PM

Sub form_load()
Dim a#, b#, c#, d#
    a = (8000 * 0.3)
    b = 8000 * 3
    c = b / 10
    d = a - c
    Text1.Text = d
    'Answer = 0
End Sub

Title: Re: Math
Post by: FrOzeN on December 17, 2005, 07:22 PM
Quote from: l2k-Shadow on December 17, 2005, 07:18 PM
I just used

Sub form_load()
Dim a As Double
    a = 8000 * 0.3 - 8000 * 3 / 10
    Text1.Text = a
End Sub

and got -8.88178419700125E-14 .. what's the problem?
The problem is that it returns the wrong answer, it should be 0.
Title: Re: Math
Post by: l2k-Shadow on December 17, 2005, 07:24 PM
Quote from: FrOzeN on December 17, 2005, 07:22 PM
Quote from: l2k-Shadow on December 17, 2005, 07:18 PM
I just used

Sub form_load()
Dim a As Double
    a = 8000 * 0.3 - 8000 * 3 / 10
    Text1.Text = a
End Sub

and got -8.88178419700125E-14 .. what's the problem?
The problem is that it returns the wrong answer, it should be 0.
Yeah I just realized that, edited my post.
Title: Re: Math
Post by: 111787 on December 17, 2005, 09:10 PM
Question: What order does it do it in?
I cant produce that answer doing it in any order.
Title: Re: Math
Post by: Adron on December 18, 2005, 12:52 AM
Quote from: 111787 on December 17, 2005, 09:10 PM
Question: What order does it do it in?
I cant produce that answer doing it in any order.

Regular math evaluation order... And copying the expression exactly as I typed it should give the nonzero result.

What I was originally doing was take 30% of an input value, and round it down to the nearest integer, i.e. Fix(x * 0.30), and this turned out to be 2399 for the input 8000. Which I thought was kinda odd...
Title: Re: Math
Post by: Tazo on December 18, 2005, 08:17 AM
which would be
Parenthesees
Exponents
Multiplication
Division
Addition
Subtraction
Title: Re: Math
Post by: rabbit on December 18, 2005, 02:39 PM
Quote from: Adron on December 18, 2005, 12:52 AM
Quote from: 111787 on December 17, 2005, 09:10 PM
Question: What order does it do it in?
I cant produce that answer doing it in any order.

Regular math evaluation order... And copying the expression exactly as I typed it should give the nonzero result.

What I was originally doing was take 30% of an input value, and round it down to the nearest integer, i.e. Fix(x * 0.30), and this turned out to be 2399 for the input 8000. Which I thought was kinda odd...
1/3 is 0.333333
Title: Re: Math
Post by: Explicit on December 18, 2005, 03:54 PM
Quote from: rabbit on December 18, 2005, 02:39 PM
Quote from: Adron on December 18, 2005, 12:52 AM
Quote from: 111787 on December 17, 2005, 09:10 PM
Question: What order does it do it in?
I cant produce that answer doing it in any order.

Regular math evaluation order... And copying the expression exactly as I typed it should give the nonzero result.

What I was originally doing was take 30% of an input value, and round it down to the nearest integer, i.e. Fix(x * 0.30), and this turned out to be 2399 for the input 8000. Which I thought was kinda odd...
1/3 is 0.333333

Where are you even getting 1/3 from?
Title: Re: Math
Post by: rabbit on December 18, 2005, 06:30 PM
I have no clue...I guess I was spacing out..

O well, it was a random fun fact I guess :P
Title: Re: Math
Post by: Explicit on December 18, 2005, 06:32 PM
Quote from: rabbit on December 18, 2005, 06:30 PM
I have no clue...I guess I was spacing out..

O well, it was a random fun fact I guess :P

Silly rabbit, fun facts are for kids!  :)
Title: Re: Math
Post by: rabbit on December 19, 2005, 10:16 AM
Wow.  That wasn't funny the first time.  Nor the second time.  Why the hell would it be funny the seven hundred twenty first time?
Title: Re: Math
Post by: iNsaNe on March 05, 2006, 04:37 PM
How is this hard. The equation is basically the same on both sides. The rule is PEMDAS stated above, Parenthesis, Exponents, Multiplication OR Division (Left to Right), Addition OR Subtraction(Left to Right).

The original equation: 8000 × 0.3 - 8000 × 3 / 10
- Since PEMDAS goes in order from Multiplication OR division from Left to Right, the "× 3 / 10" means × 0.3

The equation basically says:

= (8000 × 0.3) - (8000 × 0.3)
= 0

Why is it necessary to go in such depth?
Title: Re: Math
Post by: l2k-Shadow on March 05, 2006, 04:44 PM
Quote from: iNsaNe on March 05, 2006, 04:37 PM
How is this hard. The equation is basically the same on both sides. The rule is PEMDAS stated above, Parenthesis, Exponents, Multiplication OR Division (Left to Right), Addition OR Subtraction(Left to Right).

The original equation: 8000 × 0.3 - 8000 × 3 / 10
- Since PEMDAS goes in order from Multiplication OR division from Left to Right, the "× 3 / 10" means × 0.3

The equation basically says:

= (8000 × 0.3) - (8000 × 0.3)
= 0

Why is it necessary to go in such depth?

don't bring up 1 month+ old topics please