Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Greater than or equal evaluated to false

Subject: Greater than or equal evaluated to false

From: Peter

Date: 11 Nov, 2010 01:19:03

Message: 1 of 8

I have two numbers identical to four digits after decimal point, say 3.7890 and 3.7890. The two numbers come from MATLAB's filter function.

When I compare them in my custom function using relation operator greater than or equal (that is ">=") I get 0 which means the first number is smaller.

I changed the format of command window to "long e". The two numbers are exactly the same to every displayed decimal. Why is the first number then smaller? Why can't I see it? Is it because even "long e" format does not display all decimals (I am pretty sure it does not)? Should I compare the two numbers bitwise then?

Subject: Greater than or equal evaluated to false

From: Sean

Date: 11 Nov, 2010 01:37:04

Message: 2 of 8

"Peter " <hans21@geemaaaiill.com> wrote in message <ibfga7$5cn$1@fred.mathworks.com>...
> I have two numbers identical to four digits after decimal point, say 3.7890 and 3.7890. The two numbers come from MATLAB's filter function.
>
> When I compare them in my custom function using relation operator greater than or equal (that is ">=") I get 0 which means the first number is smaller.
>
> I changed the format of command window to "long e". The two numbers are exactly the same to every displayed decimal. Why is the first number then smaller? Why can't I see it? Is it because even "long e" format does not display all decimals (I am pretty sure it does not)? Should I compare the two numbers bitwise then?

Floating Point Arithmetic:
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2__0.1_.28or_similar.29_not_equal_to_zero.3F

Subject: Greater than or equal evaluated to false

From: ImageAnalyst

Date: 11 Nov, 2010 02:05:59

Message: 3 of 8

On Nov 10, 8:37 pm, "Sean "
<sean.dewol...@nospamplease.umit.maine.edu> wrote:
> Floating Point Arithmetic:http://matlab.wikia.com/wiki/FAQ#Why_is_....
---------------------------------------------------
Anyone know why Sean's link goes to the top of the FAQ and not
directly to the specific question as it should? It fires up a new tab
(in Firefox) and the URL looks the same as when you hover over the
contents for that question, yet it puts you at the contents instead of
at the question. If you click on the contents link, which is
identical, it does send you to the location of the question further
down in the FAQ. I don't know why one would work and the other not.

Subject: Greater than or equal evaluated to false

From: Sean

Date: 11 Nov, 2010 02:15:07

Message: 4 of 8

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <62d455e9-183c-4d20-85f5-57cc80ac120a@r29g2000yqj.googlegroups.com>...
> On Nov 10, 8:37 pm, "Sean "
> <sean.dewol...@nospamplease.umit.maine.edu> wrote:
> > Floating Point Arithmetic:http://matlab.wikia.com/wiki/FAQ#Why_is_....
> ---------------------------------------------------
> Anyone know why Sean's link goes to the top of the FAQ and not
> directly to the specific question as it should? It fires up a new tab
> (in Firefox) and the URL looks the same as when you hover over the
> contents for that question, yet it puts you at the contents instead of
> at the question. If you click on the contents link, which is
> identical, it does send you to the location of the question further
> down in the FAQ. I don't know why one would work and the other not.


It's not quite the same.
I must've accidentally deleted a '-' between two underscores, probably trying to get it all on one line. Try this:
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

Subject: Greater than or equal evaluated to false

From: ImageAnalyst

Date: 11 Nov, 2010 02:19:56

Message: 5 of 8

Hmmm.. that seemed to work. I thought you just copied and pasted so
it should have been identical, but I guess not.

Subject: Greater than or equal evaluated to false

From: James Tursa

Date: 11 Nov, 2010 04:24:04

Message: 6 of 8

"Peter " <hans21@geemaaaiill.com> wrote in message <ibfga7$5cn$1@fred.mathworks.com>...
> I have two numbers identical to four digits after decimal point, say 3.7890 and 3.7890. The two numbers come from MATLAB's filter function.
>
> When I compare them in my custom function using relation operator greater than or equal (that is ">=") I get 0 which means the first number is smaller.
>
> I changed the format of command window to "long e". The two numbers are exactly the same to every displayed decimal. Why is the first number then smaller? Why can't I see it? Is it because even "long e" format does not display all decimals (I am pretty sure it does not)? Should I compare the two numbers bitwise then?

You can use this FEX submission to see exactly what each number is:

http://www.mathworks.com/matlabcentral/fileexchange/22239-num2strexact-exact-version-of-num2str

James Tursa

Subject: Greater than or equal evaluated to false

From: Steven_Lord

Date: 11 Nov, 2010 14:54:48

Message: 7 of 8



"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message
news:ibfr54$2l9$1@fred.mathworks.com...
> "Peter " <hans21@geemaaaiill.com> wrote in message
> <ibfga7$5cn$1@fred.mathworks.com>...
>> I have two numbers identical to four digits after decimal point, say
>> 3.7890 and 3.7890. The two numbers come from MATLAB's filter function.
>>
>> When I compare them in my custom function using relation operator greater
>> than or equal (that is ">=") I get 0 which means the first number is
>> smaller.
>>
>> I changed the format of command window to "long e". The two numbers are
>> exactly the same to every displayed decimal. Why is the first number then
>> smaller? Why can't I see it? Is it because even "long e" format does not
>> display all decimals (I am pretty sure it does not)? Should I compare the
>> two numbers bitwise then?
>
> You can use this FEX submission to see exactly what each number is:
>
> http://www.mathworks.com/matlabcentral/fileexchange/22239-num2strexact-exact-version-of-num2str

Or you can display the numbers with NUM2HEX or FORMAT HEX to check if they
are different in the last bit (which I suspect they probably are.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Greater than or equal evaluated to false

From: Peter

Date: 11 Nov, 2010 15:00:33

Message: 8 of 8

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <ibfr54$2l9$1@fred.mathworks.com>...
> "Peter " <hans21@geemaaaiill.com> wrote in message <ibfga7$5cn$1@fred.mathworks.com>...
> > I have two numbers identical to four digits after decimal point, say 3.7890 and 3.7890. The two numbers come from MATLAB's filter function.
> >
> > When I compare them in my custom function using relation operator greater than or equal (that is ">=") I get 0 which means the first number is smaller.
> >
> > I changed the format of command window to "long e". The two numbers are exactly the same to every displayed decimal. Why is the first number then smaller? Why can't I see it? Is it because even "long e" format does not display all decimals (I am pretty sure it does not)? Should I compare the two numbers bitwise then?
>
> You can use this FEX submission to see exactly what each number is:
>
> http://www.mathworks.com/matlabcentral/fileexchange/22239-num2strexact-exact-version-of-num2str
>
> James Tursa

thank you all! helpful indeed.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us