473,395 Members | 1,763 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,395 software developers and data experts.

fmod?

Hi!

I'm reading a C book, and it says that fmod() returns the remainder of the
exact division of it's arguments. Well, in a exact division, the remainder
shall always be 0 (zero), so this don't make any logic (I guess).
Anyway, foward in the chapter it says that fmod returns the remainder of
the integer division of it's arguments. I checked KnR 2nd ed. and the
man page, and still can't figure out wich one is correct.
Nov 14 '05 #1
6 8079
stau writes:
I'm reading a C book, and it says that fmod() returns the remainder of the
exact division of it's arguments. Well, in a exact division, the remainder
shall always be 0 (zero), so this don't make any logic (I guess).
Anyway, foward in the chapter it says that fmod returns the remainder of
the integer division of it's arguments. I checked KnR 2nd ed. and the
man page, and still can't figure out wich one is correct.


I would go with this. Scan down to fmod.

http://www.acm.uiuc.edu/webmonkeys/b.../2.7.html#fmod

I found that on google groups with <fmod plauger>. There are more hits if
you don't like this one. I consider Plauger to be definitive in this area.

I don't like your book. It is kind of nasty to represent 0 in floating
point. AFAIK it is done by definition, rather than an actual result of
computation.
Nov 14 '05 #2
On Sun, 28 Dec 2003 04:26:25 +0000, stau <st**@pretogal.pt> wrote in
comp.lang.c:
Hi!

I'm reading a C book, and it says that fmod() returns the remainder of the
exact division of it's arguments. Well, in a exact division, the remainder
shall always be 0 (zero), so this don't make any logic (I guess).
Anyway, foward in the chapter it says that fmod returns the remainder of
the integer division of it's arguments. I checked KnR 2nd ed. and the
man page, and still can't figure out wich one is correct.


Here is how the C standard defines it:

========
7.12.10.1 The fmod functions

Synopsis

1 #include <math.h>

double fmod(double x, double y);

2 The fmod functions compute the floating-point remainder of x/y.

Returns

3 The fmod functions return the value x - ny, for some integer n such
that, if y is nonzero, the result has the same sign as x and magnitude
less than the magnitude of y. If y is zero, whether a domain error
occurs or the fmod functions return zero is implementation defined.
========

No use is made of the word "exact".

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 14 '05 #3
stau wrote:
Hi!

I'm reading a C book, and it says that fmod() returns the remainder of the
exact division of it's arguments. Well, in a exact division, the remainder
shall always be 0 (zero), so this don't make any logic (I guess).
Anyway, foward in the chapter it says that fmod returns the remainder of
the integer division of it's arguments. I checked KnR 2nd ed. and the
man page, and still can't figure out wich one is correct.


I don't know what you mean by "exact division." In modular
division, if the divisor is a factor of the dividend the result
will be zero, i.e. no remainder. The library function fmod()
returns the remainder after division with floating point numbers
(fractional numbers). It returns type double and its arguments
must be doubles. Remember to #include <math.h>. If you want the
remainder after division with integers use the % operator. Its
operands must be ints.

Nov 14 '05 #4
On Sun, 28 Dec 2003 18:15:43 +0000, John Smith wrote:

Sorry, by exact division I meant real division (real arithmetic).
That expression is used in my native language.

Thanks.
Nov 14 '05 #5
In article <pa****************************@pretogal.pt> stau <st**@pretogal.pt> writes:
Sorry, by exact division I meant real division (real arithmetic).
That expression is used in my native language.


And it indeed is (but not necessarily). I think when your book indeed
states that fmod performs an exact division it is wrong. What it does
do is calculate an exact *integral* quotient and then it returns the
associated remainder.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 14 '05 #6
On Tue, 30 Dec 2003 00:40:18 +0000, Dik T. Winter wrote:
In article <pa****************************@pretogal.pt> stau <st**@pretogal.pt> writes:
[SNIP]
And it indeed is (but not necessarily). I think when your book indeed
states that fmod performs an exact division it is wrong. What it does
do is calculate an exact *integral* quotient and then it returns the
associated remainder.


Yes, I reallized that. The book gives a wild pointer when he states that
the fmod function returns the remainder of a real division.

Nov 14 '05 #7

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

Similar topics

2
by: Zunbeltz Izaola | last post by:
Hi, I have a problem with % operation. It returns a incorrect value in this case: >>> -2.77555756156e-17%1 1.0 where the returned value should be -2.77555756156e-17.
8
by: seia0106 | last post by:
Hello, I have a C++ program , which has following two lines of code z=atan2(x,y); z=(float)(fmod(2*pi+z, 2*pi); The comments written by the other programmer says that second line is used to...
2
by: Lonnie Princehouse | last post by:
I've been trying to debug this for two days now, and it's a longshot but I'm hoping that someone here might recognize a solution. I've got a C extension which calls a function in a C library,...
2
by: Gintautas | last post by:
I'm trying to play a part of wav file. FSOUND_Sample_Load (0,"T01.wav",FSOUND_NORMAL, 0,0); plays all file FSOUND_Sample_Load (0,"T01.wav",FSOUND_NORMAL, 0,90000); plays file until 90000 sample...
17
by: joseph.p.doyle | last post by:
This code, compiled with visual studio .NET 2003, double a = 95.022, b = 0.01; printf ("%lf - floor(%lf / %lf) * %lf = %.17lf\n", a, a, b, b, a - floor(a / b) * b); a = 95.021, b = 0.01;...
14
by: Aaron Gray | last post by:
Does anyone have a good fmod() function written in Javascript ? Many thanks in advance, Aaron
7
by: bummerland | last post by:
Hi, I have a problem with the function fmod. Why is fmod(5.7, 0.1) = 0.1 ?? Why is it not 0? tia bummerland
12
by: bsabiston | last post by:
Hi, I'm trying to get the fractional part of a floating point number. I've tried fmod() and modf(), and while both do work, they also occasionally return 1.0 for the fractional part of the number...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.