I How to solve an equation with FMOD in it

  • I
  • Thread starter Thread starter 1plus1is10
  • Start date Start date
AI Thread Summary
The discussion revolves around simplifying the equation a = FMOD(((x*y)-z), x) / x by replacing FMOD with algebraic expressions. Participants clarify that FMOD, specifically in C and C++, returns the floating-point remainder, which complicates algebraic manipulation due to its reliance on the FLOOR function. Suggestions include using integer casting to eliminate fractional parts, but the original poster expresses frustration over the difficulty of transforming FLOOR into basic algebra. Ultimately, they conclude that simplifying the equation may not be feasible and decide to accept the current method. The conversation highlights the challenges of integrating programming functions with algebraic concepts.
1plus1is10
Messages
51
Reaction score
0
TL;DR Summary
Replace FMOD with algebraic math
I have:
a = FMOD(((x*y)-z), x) / x

When I look at this, I think it could most likely be simplified algebraically if I could only replace FMOD with algebraic math.
After searching the web, I realize that this is more than I would know how to do since FMOD uses FLOOR.

Anyway, I thought I would ask here to see if my function can be simplified somehow (hopefully without FMOD).
Thanks
 
Mathematics news on Phys.org
You may transform it by function as
mod(m,n)=m-n\lfloor \frac{m}{n} \rfloor
 
  • Like
Likes 1plus1is10
1plus1is10 said:
Summary:: Replace FMOD with algebraic math

I have:
a = FMOD(((x*y)-z), x) / x
In C and C++, fmod is the floating point modulus. Is that how you're using this function?

If so, I don't think the mod function that @anuttarasammyak mentioned will be helpful. fmod(x, y) returns the floating point remainder of x divided by y. For example, fmod(5.0, 4.0) would return 0.25.
Correction: the return value is 1.0
 
Last edited:
  • Like
Likes anuttarasammyak
Actually fmod(5.0, 4.0) is 1.0 and anuttarasammyak is on the right path with converting it that way.

You can test it here
http://cpp.sh/

#include <iostream>
#include <cmath>
int main(){ std::cout << fmod(5.0, 4.0); }The problem becomes, I have no idea how to do algebra with FLOOR unless it can be "transformed" or replaced somehow also.
Thanks
 
std::cout << 5.0-(4.0*floor(5.0/4.0));
 
The usual notation for FLOOR(x) is \lfloor x \rfloor.
 
Yes, I know. I just do not know math markup code.
 
1plus1is10 said:
Actually fmod(5.0, 4.0) is 1.0
Bad example from me, caused by not checking some code and from not using this function for a long time. The mod function returns an integer, but fmod's return value is a double or a float, depending on the arguments to it, that may or may not be the float/double equivalent of an integer.
Here's a better example to show what I mean:
C:
double rem = fmod(3.5, 3.0);
After execution, rem will be set to 0.5.
 
  • Like
Likes 1plus1is10
1plus1is10 said:
The problem becomes, I have no idea how to do algebra with FLOOR unless it can be "transformed" or replaced somehow also.
You can cast a float or double to type int, which will get rid of any fraction part, which is equivalent to what floor() does.
For example:
C:
double dVal = 4.3;
int iVal = static_cast<int>(dVal);
iVal will be set to 4 .
 
  • #10
Mark44,
I appreciate the fact you know C++ which is what I use to perform calculations. But this for me really is a "converting-to-basic-algebra" problem at the moment.

I'm posting my "Math Notes" for you to get an idea of what I typically use to help me:
[CODE title="Math Notes"] A1 A2 A3 A4
(x/y)*z = x/(y/z) = x*(z/y) = (x*z)/y
(1/2)*3 = 1/(2/3) = 1*(3/2) = (1*3)/2
0.5*3 = 1/0.666 = 1*1.5 = 3/2
1.5 = 1.5 = 1.5 = 1.5

B1 B2 B3 B4:B3 B5:B4,A3,A2 B6:B5,B1,B2 B7:B6,A3,A2
(x/y)/z = x/(y*z) = (x/z)/y = (1/y)*(x/z) = (1/y)/(z/x) = 1/(y*(z/x)) = 1/(y/(x/z))
(1/2)/3 = 1/(2*3) = (1/3)/2 = (1/2)*(1/3) = (1/2)/(3/1) = 1/(2*(3/1)) = 1/(2/(1/3))
0.5/3 = 1/6 = 0.333/2 = 0.5*0.333 = 0.5/3 = 1/(2*3) = 1/(2/0.333)
0.1666 = 0.1666 = 0.1666 = 0.1666 = 0.1666 = 0.1666 = 0.1666

1=A1 1=A2 1=A3 1=A4
a=(x/y)*z, a=x/(y/z), a=x*(z/y), a=(x*z)/y
a/z=(x/y), a*(y/z)=x, a/(z/y)=x, a*y=(x*z)
1/z=(x/y), 1*(y/z)=x, 1/(z/y)=x, 1*y=(x*z)
^ (y/z)=x, <-x-^ y=(x*z)=(z*x)
^ (y/z)=1/(z/y), y/x=z
1/(y/x)=(x/y) <--substitute z---------^

1=B1 1=B2 1=B3 1=B4
a=(x/y)/z, a=x/(y*z), a=(x/z)/y, a=(1/y)/(z/x)
a*z=(x/y), a*(y*z)=x, a*y=(x/z), a*(z/x)=(1/y)
1*z=(x/y), 1*(y*z)=x, 1*y=(x/z), 1*(z/x)=(1/y)
z=(x/y), (y*z)=x, y=(x/z), (z/x)=(1/y) sub y (z/x)=1/(x/z)
z*y=x, y=x/z, y*z=x z=(1/y)*x sub z (x/y)=(1/y)*x[/CODE]

And, of course, I am aware that not everything can be converted to basic algebra (oh well).
But if FLOOR can be, then that would be nice.
Thanks, again.
 
  • #11
Back
Top