Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-15-2011, 07:29 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 22
verbatimbot is on a distinguished road
Default Why cant I get dividing remainder of two float numbers?

Hello,

Why XCode does not let me to calculate dividing remainder of a two float numbers like:
Code:
int remainder = rate % 0.2F; // rate is float
but it does let me with integers.
verbatimbot is offline   Reply With Quote
Old 06-15-2011, 07:43 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Can you be more specific when you say it won't let you?
harrytheshark is offline   Reply With Quote
Old 06-15-2011, 07:46 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Paris, France
Posts: 946
7twenty7 is on a distinguished road
Default

Quote:
Originally Posted by verbatimbot View Post
Hello,

Why XCode does not let me to calculate dividing remainder of a two float numbers like:
Code:
int remainder = rate % 0.2F; // rate is float
but it does let me with integers.
The % operator only works with integers...use fmod().
7twenty7 is offline   Reply With Quote
Old 06-15-2011, 07:48 AM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by verbatimbot View Post
Hello,

Why XCode does not let me to calculate dividing remainder of a two float numbers like:
Code:
int remainder = rate % 0.2F; // rate is float
but it does let me with integers.
By definition, remainder is an integer function. The remainder is the integer left over when you divide one integer by another. When you divide floating point numbers, the result is another floating point number.

Floating point remainder does not make any sense.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-20-2011, 07:32 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Location: West Palm Beach, FL
Posts: 1
tgurus is on a distinguished road
Talking

Quote:
Originally Posted by Duncan C View Post
By definition, remainder is an integer function. The remainder is the integer left over when you divide one integer by another. When you divide floating point numbers, the result is another floating point number.

Floating point remainder does not make any sense.


UM....wrong, wrong and wrong. Remainder is definitely NOT an integer by definition, nor is it an integer-only function. By definition, the remainder of a division operation is the result of subtracting the integral quotient multiplied by the denominator from the numerator:

as in remainder = numerator - quotient * denominator

The integral quotient (a derived result, not supplied in your formula) is the ONLY number that is always an integer in this basic mathematic formula. When calculating a remainder, the results are ALWAYS an integral quotient and a remainder, which may or may not be an integer, of course. That is the definition.

It most certainly does not matter if the numerator and/or denominator are integers or not, except when programming, lol... someone needs to whip out their 5th grade math book.

7twenty7 got it right! Correct code should be
Code:
 float remainder = fmod(rate,0.2f);
fmod reference here: fmod - C++ Reference

Last edited by tgurus; 11-20-2011 at 07:58 AM.
tgurus is offline   Reply With Quote
Reply

Bookmarks

Tags
arithmetic, dividing remainder

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 312
6 members and 306 guests
chemistry, Dnnake, iOS.Lover, lendo, Leslie80, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:24 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0