473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I do floating point Remainder function in C++?

Morning, group:

How do I code floating point modulus function?
What I need is

double a;
double b;
double c;

a = 2.3;
b = 1.2;

c = a % b; // invalid operands of types `double' and `int' to binary `

TIA.
May 4 '06 #1
5 21210

"Phlip" <ph******@yahoo.com> wrote in message
news:MB******************@newssvr30.news.prodigy.c om...
http://www.opengroup.org/onlinepubs/.../xsh/fmod.html ?

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!


Thankk you.
May 4 '06 #3
a - b*int(a/b) or fmod() should do the trick.

May 4 '06 #4
a - b*int(a/b) or fmod() should do the trick.


when b == 0, you're busted. When a/b > MAX_INT, the result is wrong.

Use fmod, which basically does:
f = a/b - floor(a/b);


May 4 '06 #5
std::fmod even better.

May 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DvGrimm | last post by:
Any help would be very, very much appreciated... I've been searching the net (google) for 4 days now trying to find a php function to convert hex to floating point. I'm converting old...
14
by: Amit Bhatia | last post by:
Hi there. I am cross posting this on comp.lang.c as well: sorry for same. The problem I am facing is as follows: For example: double a= 0.15; double b=2.4; const double VERYTINY =1.e-10; I...
5
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are...
12
by: Dave Rahardja | last post by:
Does the C++ standard specify the behavior of floating point numbers during "exceptional" (exceptional with respect to floating point numbers, not exceptions) conditions? For example: double...
25
by: Gaurav Verma | last post by:
Hi, I want to convert a floating point number (or a decimal number say 123.456) into binary notation using a C program. Can somebody help me out with it? Thanks Gaurav --...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
5
by: ME | last post by:
What is the fastest way of getting the fraction part of a floating point number? So, if I have a float 10.3 I want to get a float with value 0.3 fast. Thanks
8
by: vendredi5h | last post by:
Hello all, I'd like to split a 64-bits word (hold as a floating point number) into two 32-bits words (hold as integers). Bitwise operators are working on Integers, not on floating point. ...
4
by: SD14 | last post by:
for some reason in my program when i try and add a number to my current number i get a floating point exception now i have narrowed down were it stops working to line 398 but i dont know as to why it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.