cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
% (mod) for floats
% (mod) for floats
Aug 7, 2012 at 1:16am UTC
beakie
(166)
Need some code to perform a mod style algorithm on floats or doubles.
So... 123.2 % 3 = 0.2
Any ideas?
Aug 7, 2012 at 1:20am UTC
Disch
(13742)
1
2
// goal: result = orig % mod
result = orig - ( (
int
)(orig / mod) * mod );
Aug 7, 2012 at 1:28am UTC
beakie
(166)
Funky. Nice one.
Aug 7, 2012 at 8:52am UTC
Peter87
(11234)
You can use std::fmod
http://www.cplusplus.com/reference/clibrary/cmath/fmod/
Aug 7, 2012 at 3:36pm UTC
Disch
(13742)
oh yeah.. duh. I always forget fmod exists because I confuse it for modf.
Topic archived. No new replies allowed.