Divide and get whole number
Is there a function that will divide a number by another number and return the amount of times it can be divided into it evenly?
I know only that which I know, but I do not know what I know.
If I understand what you are saying then no. Righting a function to do that wouldn''t be too hard though. Let''s see....
This function should work if I understand the problem correctly. Hope it helps!!!
Scout
Visit Subversive Systems!!!
--Remember, be quick to listen, slow to speak, and slow to get angry.
|
This function should work if I understand the problem correctly. Hope it helps!!!
Scout
Visit Subversive Systems!!!
--Remember, be quick to listen, slow to speak, and slow to get angry.
ScoutVisit Subversive Systems!!!--Remember, be quick to listen, slow to speak, and slow to get angry.
just do this
"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
|
"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
Of course, if you''re looking at floating point numbers....
...
You can just cast the floating point result to an int:
float a = 0.00072314678;
float b = 0.000115233;
(I picked small examples so the int approach would fail without scaling the numbers)
int result = (int)(a/b) = 6
Is that correct? Lets see.
6*115.223 = 0.000691398
The remainder is then 0.00072314678 - 0.000691398 = 0.00003174878
which is less than the number we were diving by.
So, (int)(a/b) is a way to do it for floating point numbers!
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
![](smile.gif)
You can just cast the floating point result to an int:
float a = 0.00072314678;
float b = 0.000115233;
(I picked small examples so the int approach would fail without scaling the numbers)
int result = (int)(a/b) = 6
Is that correct? Lets see.
6*115.223 = 0.000691398
The remainder is then 0.00072314678 - 0.000691398 = 0.00003174878
which is less than the number we were diving by.
So, (int)(a/b) is a way to do it for floating point numbers!
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
I don''t know of any language where given
int a = 99
int b = 10
a devided by b will not be 9.
Or you could do (a-(a%b))/b in C and get exactly the same thing.
int a = 99
int b = 10
a devided by b will not be 9.
Or you could do (a-(a%b))/b in C and get exactly the same thing.
As I said earlier, the function div , which is implemented in the C standard library, and almost every mathematical package for other languages that I can think of, provides the answer you seek. It performs the computation that Graham indicated.
Actually the C version returns a div_type, which stores the quotient and remainder of the division.
Regards,
Timkin
Actually the C version returns a div_type, which stores the quotient and remainder of the division.
Regards,
Timkin
quote:
Original post by Timkin
As I said earlier, the function div , which is implemented in the C standard library, and almost every mathematical package for other languages that I can think of, provides the answer you seek. It performs the computation that Graham indicated.
The one condition being that div takes integer arguments and produces integer results.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement