For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > November 2005 > Divide by 0 error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Divide by 0 error
DanS

2005-11-24, 7:55 am

Hey there,

The shell REPLACEMENT app I have been working on is going well.

There was a discussion here about Globals Hooks several months back if
you may recall. I ended up using PowerBasic to create a 'real' DLL to
install the hook I needed, which is so far the only non-VB part of it.

I'm now working on the desktop replacement, and have received this error.
I'm not sure why yet, by that is neither here nor there, as the question
is how is this error triggered ?

4 / 2 = 2

2 x 2 = 4

4 / 0 = error, because you can't multiple anything by 0 to get 4.

In my app, I'm using GetWindowRect(), and then saving a H:W ratio by
doing

hRatio = h/w or w/h, can't remember, but not important. In certain
instances, the GetWindowRect returns either all 0's in the rect
structure, or a top and bottom that are the same, and a left and right
that are the same (haven't looked at the rect structure yet, althought
that doesn't matter anyway in regards to the question).

Anywho, to make a short question even longer than it needed to be, I end
up with a window height of 0 and a window width of 0.

Therefore, the hRatio function above evaluates as:

hRatio = 0 / 0

Which throws the 'divide by zero' error at me.

IMO, this is NOT an error, since 0 x 0 does = 0.

Should this really be an error ?

Thanks,

DanS



Larry Lard

2005-11-24, 6:55 pm


DanS wrote:
[snip]
> Therefore, the hRatio function above evaluates as:
>
> hRatio = 0 / 0
>
> Which throws the 'divide by zero' error at me.
>
> IMO, this is NOT an error, since 0 x 0 does = 0.
>
> Should this really be an error ?


By the same logic, 0/0 = 1, since 0x1 = 0. Also, 0/0 = 2, since 0x2 =
0. Etc. It's undefined for a good reason :)

--
Larry Lard
Replies to group please

Bob Butler

2005-11-24, 6:55 pm

"DanS" <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote in message
news:Xns97185B515C06idispcom@216.196.97.142
> to make a short question even longer than it needed to be, I
> end up with a window height of 0 and a window width of 0.
> Therefore, the hRatio function above evaluates as:
> hRatio = 0 / 0
> Which throws the 'divide by zero' error at me.
> IMO, this is NOT an error, since 0 x 0 does = 0.


so does 1x0, 2x0, 3x0, etc; there is no defined answer when dividing by
zero so it is an error.

> Should this really be an error ?


Yes.

You will have to test for it and handle it
if denom = 0 then
ratio=0
else
ratio=num/denom
end if

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

DanS

2005-11-24, 6:55 pm

"Larry Lard" <larrylard@hotmail.com> wrote in news:1132841053.791601.246080
@o13g2000cwo.googlegroups.com:

>
> DanS wrote:
> [snip]
>
> By the same logic, 0/0 = 1, since 0x1 = 0. Also, 0/0 = 2, since 0x2 =
> 0. Etc. It's undefined for a good reason :)
>


ahhhh yes. fair enough.
DanS

2005-11-24, 6:55 pm

"Bob Butler" <tiredofit@nospam.com> wrote in news:uOsYlJQ8FHA.636
@TK2MSFTNGP10.phx.gbl:

> "DanS" <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote in message
> news:Xns97185B515C06idispcom@216.196.97.142
>
> so does 1x0, 2x0, 3x0, etc; there is no defined answer when dividing by
> zero so it is an error.
>
>
> Yes.
>
> You will have to test for it and handle it
> if denom = 0 then
> ratio=0
> else
> ratio=num/denom
> end if
>


OK, agreed, as I didn't think that deeply into it. I was just pondering the
numbers I was receiving.
J French

2005-11-24, 6:55 pm

On Thu, 24 Nov 2005 07:52:56 -0600, DanS
<t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> wrote:

<snip>

>Therefore, the hRatio function above evaluates as:
>
>hRatio = 0 / 0
>
>Which throws the 'divide by zero' error at me.
>
>IMO, this is NOT an error, since 0 x 0 does = 0.
>
>Should this really be an error ?


Philosophically speaking, probably not

But someone forgot to tell that to Intel's engineers

Being a programmer you can write your own Div( A, B ) function and
rearrange the rules as you see fit.
JLuis Estrada

2005-11-26, 6:55 pm

Thats is a mathematical error called limits produced by this:

supose you have 2 numbers: A and B,

supose that A = 1 and B = 1

y you divide A over B you get 1 (1 / 1 = 1)

now lets make B = .5 ( or 1/2 ) and lets do the same operation

(1 / .5 = 2)

and if we make B smaller, the results increases!!!

this is, the result is inversely proportional to B

so, if we make the B so so small so it tends to 0, the results tends to
infinite

this is

lim 1 / B = infinite
B -> 0

and mathematically is imposible to define this operation because its
imposible to define infinite.
And this is even harder to define in the computer (no matter how many bites
you have)

thats why any time you divide any numer by zero (even the 0 itself) always
launches an error!!!!!
hope this help you to understan why this happened!

regards jluis

"DanS" <t.h.i.s.n.t.h.a.t@a.d.e.l.p.h.i.a..n.e.t> escribió en el mensaje
news:Xns97185B515C06idispcom@216.196.97.142...
> Hey there,
>
> The shell REPLACEMENT app I have been working on is going well.
>
> There was a discussion here about Globals Hooks several months back if
> you may recall. I ended up using PowerBasic to create a 'real' DLL to
> install the hook I needed, which is so far the only non-VB part of it.
>
> I'm now working on the desktop replacement, and have received this error.
> I'm not sure why yet, by that is neither here nor there, as the question
> is how is this error triggered ?
>
> 4 / 2 = 2
>
> 2 x 2 = 4
>
> 4 / 0 = error, because you can't multiple anything by 0 to get 4.
>
> In my app, I'm using GetWindowRect(), and then saving a H:W ratio by
> doing
>
> hRatio = h/w or w/h, can't remember, but not important. In certain
> instances, the GetWindowRect returns either all 0's in the rect
> structure, or a top and bottom that are the same, and a left and right
> that are the same (haven't looked at the rect structure yet, althought
> that doesn't matter anyway in regards to the question).
>
> Anywho, to make a short question even longer than it needed to be, I end
> up with a window height of 0 and a window width of 0.
>
> Therefore, the hRatio function above evaluates as:
>
> hRatio = 0 / 0
>
> Which throws the 'divide by zero' error at me.
>
> IMO, this is NOT an error, since 0 x 0 does = 0.
>
> Should this really be an error ?
>
> Thanks,
>
> DanS
>
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com