How to solve an equation with FMOD in it

  • I
  • Thread starter 1plus1is10
  • Start date
In summary, the conversation discusses replacing the FMOD function with algebraic math, specifically converting it to the floor function. However, it is noted that fmod returns a floating point value, while floor returns an integer, making it difficult to convert directly. Further research reveals that it is not possible to rewrite the floor function using only basic algebra, making it impractical to replace FMOD with algebraic math.
  • #1
1plus1is10
51
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
  • #2
You may transform it by function as
[tex]mod(m,n)=m-n\lfloor \frac{m}{n} \rfloor[/tex]
 
  • Like
Likes 1plus1is10
  • #3
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
  • #4
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
 
  • #5
std::cout << 5.0-(4.0*floor(5.0/4.0));
 
  • #6
The usual notation for FLOOR(x) is [itex]\lfloor x \rfloor[/itex].
 
  • #7
Yes, I know. I just do not know math markup code.
 
  • #8
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
  • #9
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:
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

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

1. What is FMOD in an equation?

FMOD stands for "floating-point modulus" and it is a mathematical operation that calculates the remainder after dividing two numbers. It is commonly used in computer programming to solve equations involving fractions or decimals.

2. How do I use FMOD in an equation?

To use FMOD in an equation, you first need to identify which numbers you want to divide. Then, you can use the FMOD function in your programming language to calculate the remainder. The syntax may vary depending on the language, but the basic formula is "FMOD(a, b)", where a is the dividend and b is the divisor.

3. Can FMOD be used with negative numbers?

Yes, FMOD can be used with negative numbers. The result will follow the same rules as regular division, where the remainder is always positive and less than the divisor. For example, FMOD(-10, 3) will result in 2.

4. What is the difference between FMOD and MOD?

FMOD and MOD (modulo) are both mathematical operations that calculate remainders. The main difference is that FMOD works with floating-point numbers, while MOD only works with integers. This means that FMOD can handle decimal numbers, while MOD will round down any decimal values.

5. In what situations would I need to use FMOD in an equation?

FMOD is commonly used in equations involving fractions or decimals, as it allows for more precise calculations. It can also be used to solve problems involving periodic functions, such as finding the day of the week or the time of day. Additionally, FMOD can be used in programming to handle edge cases or errors in calculations involving division.

Similar threads

Replies
2
Views
267
Replies
10
Views
1K
Replies
18
Views
2K
  • General Math
Replies
2
Views
729
Replies
2
Views
1K
Replies
26
Views
2K
Replies
4
Views
764
Replies
4
Views
1K
Replies
2
Views
726
Replies
1
Views
735
Back
Top