fmod() in VB 
Author Message
 fmod() in VB

Hi

I need an algorithm for the C++ function fmod() but in VB.
I tried Mod but it truncates values and gives division by zero errors
Can anybody help?

TIA
k



Fri, 21 Nov 2003 06:40:38 GMT  
 fmod() in VB
I'm not familiar with the fmod() function from C++, what is it supposed to do. Can you
describe it and give some examples of the input and expected output so I can see how it
works.

Rick


Quote:
> Hi

> I need an algorithm for the C++ function fmod() but in VB.
> I tried Mod but it truncates values and gives division by zero errors
> Can anybody help?

> TIA
> k



Fri, 21 Nov 2003 10:39:17 GMT  
 fmod() in VB
Public Function FMod(ByVal dA as Double, ByVal dB as Double) As Double
  Dim dR as Double

  dR = (dA/dB) - Int(dA/dB)

  FMod = dR
End Function

Not that this function will generate an error as dB approaches zero.  Also,
you may have to resolve some differences for negative values.


Quote:
> Hi

> I need an algorithm for the C++ function fmod() but in VB.
> I tried Mod but it truncates values and gives division by zero errors
> Can anybody help?

> TIA
> k



Fri, 21 Nov 2003 10:42:52 GMT  
 fmod() in VB
It's a floating point remainder function.  I didn't know this either,
but I've got a C++ manual next to me that says simply:

float fmod(float x, float y);

The fmod() returns the remainder of x/y.


Quote:
> I'm not familiar with the fmod() function from C++, what is it supposed to
do. Can you
> describe it and give some examples of the input and expected output so I
can see how it
> works.

> Rick



> > Hi

> > I need an algorithm for the C++ function fmod() but in VB.
> > I tried Mod but it truncates values and gives division by zero errors
> > Can anybody help?

> > TIA
> > k



Fri, 21 Nov 2003 11:03:23 GMT  
 fmod() in VB
My interpretation of the fmod function (I don't do C++ so check for accuracy
before using).  You may also want to round the result to minimize floating
point errors.

Public Function fmod(ByVal x As Double, _
                                     ByVal y As Double) As Double

    If y = 0 Then y = y + 1E-199    'Prevents div by 0 error
    fmod = ((x / y) - Fix(x / y)) * y

End Function

David


Quote:
> Hi

> I need an algorithm for the C++ function fmod() but in VB.
> I tried Mod but it truncates values and gives division by zero errors
> Can anybody help?

> TIA
> k



Fri, 21 Nov 2003 12:08:43 GMT  
 fmod() in VB
Such a function seem totally worthless to me. Who could possibly care what is left over if
you divide 12.3456789 by 9.87654321 (or any other floating point division)? And of course,
with the inaccuracies that can result in representing decimal numbers in the internal
binary storage mechanism of computers, how accurate is the answer? Surely it is not
accurate to the full limit of the data type (Single or Double)? I would love for
Kyriakides to post the (real world) problem he wishes to solve where this function has
usefulness.

Rick


Quote:
> It's a floating point remainder function.  I didn't know this either,
> but I've got a C++ manual next to me that says simply:

> float fmod(float x, float y);

> The fmod() returns the remainder of x/y.



> > I'm not familiar with the fmod() function from C++, what is it supposed to
> do. Can you
> > describe it and give some examples of the input and expected output so I
> can see how it
> > works.

> > Rick



> > > Hi

> > > I need an algorithm for the C++ function fmod() but in VB.
> > > I tried Mod but it truncates values and gives division by zero errors
> > > Can anybody help?

> > > TIA
> > > k



Fri, 21 Nov 2003 14:26:54 GMT  
 fmod() in VB
Not that I have ever had a use for fmod, but somebody must - it has been a
part of the C standard library for sometime (declared in math.h or for you
C++ types cmath).

Tom Shelton


Quote:
> Such a function seem totally worthless to me. Who could possibly care what
is left over if
> you divide 12.3456789 by 9.87654321 (or any other floating point

division)? And of course,
Quote:
> with the inaccuracies that can result in representing decimal numbers in
the internal
> binary storage mechanism of computers, how accurate is the answer? Surely
it is not
> accurate to the full limit of the data type (Single or Double)? I would
love for
> Kyriakides to post the (real world) problem he wishes to solve where this
function has
> usefulness.

> Rick



> > It's a floating point remainder function.  I didn't know this either,
> > but I've got a C++ manual next to me that says simply:

> > float fmod(float x, float y);

> > The fmod() returns the remainder of x/y.



> > > I'm not familiar with the fmod() function from C++, what is it
supposed to
> > do. Can you
> > > describe it and give some examples of the input and expected output so
I
> > can see how it
> > > works.

> > > Rick



> > > > Hi

> > > > I need an algorithm for the C++ function fmod() but in VB.
> > > > I tried Mod but it truncates values and gives division by zero
errors
> > > > Can anybody help?

> > > > TIA
> > > > k



Fri, 21 Nov 2003 14:36:11 GMT  
 fmod() in VB
Thanks for the answers. I am going to try the algorithms.

Quote:
>I would love for
>Kyriakides to post the (real world) problem he wishes to solve where this
function has
>usefulness.

I need this function for a parser, meaning, I am not solving any problem
with it I just have to provide the function.

Thanks again
k



Fri, 21 Nov 2003 16:55:26 GMT  
 fmod() in VB
Hi

Just to let you know that I tested both functions and David's solution came
out correct for all the tests (all values rounded to the 6th and against
C++'s fmod calculated values) whereas Grinder's failed to produce correct
values with most values.

Both were tested against a set of 500 random values and one other with 1024
non random values.

Thanks
k


Quote:
> My interpretation of the fmod function (I don't do C++ so check for
accuracy
> before using).  You may also want to round the result to minimize floating
> point errors.

> Public Function fmod(ByVal x As Double, _
>                                      ByVal y As Double) As Double

>     If y = 0 Then y = y + 1E-199    'Prevents div by 0 error
>     fmod = ((x / y) - Fix(x / y)) * y

> End Function

> David



> > Hi

> > I need an algorithm for the C++ function fmod() but in VB.
> > I tried Mod but it truncates values and gives division by zero errors
> > Can anybody help?

> > TIA
> > k



Fri, 21 Nov 2003 17:28:22 GMT  
 fmod() in VB
Arrgh!  You were asking us to do your homework!


Quote:
> Thanks for the answers. I am going to try the algorithms.

> >I would love for
> >Kyriakides to post the (real world) problem he wishes to
solve where this
> function has
> >usefulness.

> I need this function for a parser, meaning, I am not solving
any problem
> with it I just have to provide the function.

> Thanks again
> k



Sat, 22 Nov 2003 05:06:48 GMT  
 fmod() in VB
Quote:
> Grinder's failed to produce correct values with most values.
>Biff<



Sat, 22 Nov 2003 08:09:31 GMT  
 fmod() in VB


Quote:
> Arrgh!  You were asking us to do your homework!

After reading my own post even I got that impression :) but it isn't.
This app generates C++ and VB code from mathematic expressions and, though I
know C++ fairly well I can't say the something for VB.

k



Sat, 22 Nov 2003 16:35:12 GMT  
 fmod() in VB
Sorry Grinder. It wasn't supposed to sound bad, I just wanted to give back
my own conclusions to the group.
k

Quote:
> > Grinder's failed to produce correct values with most values.
> >Biff<



Sat, 22 Nov 2003 16:36:13 GMT  
 fmod() in VB
That's totally fair--I agree completely.  I just didn't want to
say "d'oh"


Quote:
> Sorry Grinder. It wasn't supposed to sound bad, I just wanted
to give back
> my own conclusions to the group.
> k


> > > Grinder's failed to produce correct values with most
values.
> > >Biff<



Sun, 23 Nov 2003 03:17:12 GMT  
 fmod() in VB


Quote:
> Sorry Grinder. It wasn't supposed to sound bad, I just wanted to give back
> my own conclusions to the group.
> k

That was very considerate of you, thank you.

LFS



Sun, 23 Nov 2003 20:44:42 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Detecting Mouse Click in Non-VB or VB app (in VB 6)

2. vb MSCOMM Control works in VB 5 and not VB 6

3. Debugging VB Usercontrols in VB without 2nd VB Test project

4. optimizing performance and data transfer vb->excel and vb->vb

5. optimizing performance and data transfer vb->excel and vb->vb

6. convert vb 3.1 to vb 6.0

7. ? Convert Macro to VB using VB

8. How can I convert this Excel VB code to Access VB

9. vb/access ?'s, newbie to vb from c++

10. VB 6.0 and VB 6.3 for applications incompatibility

11. Call another VB program(exe) in VB

12. openning word from vb or vb.net

 

 
Powered by phpBB® Forum Software