[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fractional remainder
From: |
David Bateman |
Subject: |
Re: fractional remainder |
Date: |
Mon, 26 Dec 2005 09:57:04 +0100 |
User-agent: |
Mozilla Thunderbird 0.8 (X11/20040923) |
kamaraju kusumanchi wrote:
blah BLABBER wrote:
Howdy folks,
Question: I am a new Octave user and cannot figure out how to grab
the remainder of a fraction. For example, if I take 3/4 = 0.75, I
just want to grab the 75.
Reason: I would like to check if the remainder is zero in order to
determine if a number is odd or even. Any even number divided by 2
will have a remainder of 0, odd numbers will not. I am using this for
loop control.
Problem: In Octave, rem(3,4) gives 3. Obviously I do not understand
this function. Can you please suggest the appropriate function to use.
Thanks.
Try the mod function.
octave:1> mod(11,2)
ans = 1
octave:2> mod(10,2)
ans = 0
octave:3> mod(3,4)
ans = 3
octave:4> mod(7,4)
ans = 3
To read about a function you can use the help command. To read about
rem, type help rem at the octave prompt etc.,
hth
raju
If your goal is to see if an integer is odd/even try the bitand
function. In C the typical way to check if an integer is odd if
if (val & 1)
/* This value is odd */
else
/* This value is even */
The equivalent in octave would be
if (bitand (val, 1))
# This value is odd
else
# This value is even
endif
This should probably be faster than mod.
D.
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------