Author 
Message 
Kyriakide #1 / 15

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 


Rick Rothstei #2 / 15

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 


Grinde #3 / 15

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 


Grinde #4 / 15

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 


David Youngbloo #5 / 15

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 + 1E199 '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 


Rick Rothstei #6 / 15

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 


Tom Shelto #7 / 15

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 


Kyriakide #8 / 15

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 


Kyriakide #9 / 15

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 + 1E199 '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 


Jon Olive #10 / 15

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 


Grinde #11 / 15

fmod() in VB
Quote: > Grinder's failed to produce correct values with most values. >Biff<

Sat, 22 Nov 2003 08:09:31 GMT 


Kyriakide #12 / 15

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 


Kyriakide #13 / 15

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 


Jon Olive #14 / 15

fmod() in VB
That's totally fairI 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 


Larry Serflate #15 / 15

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 

