Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what is eps in C/C++

2 views
Skip to first unread message

Joeri Verbiest

unread,
Apr 3, 2002, 2:17:46 PM4/3/02
to
Hi,

I have a small question. In matlab we have eps to look what the floating
point relative accurancy is. Is there also a function in C/C++ for doing
this.

Thanks


Joeri

Victor Bazarov

unread,
Apr 3, 2002, 2:48:25 PM4/3/02
to
"Joeri Verbiest" <joeri.v...@ieee.org> wrote...

> I have a small question. In matlab we have eps to look what the floating
> point relative accurancy is. Is there also a function in C/C++ for doing
> this.


In C++ there is std::numeric_limits<double>::epsilon() function
and std::numeric_limits<float>::epsilon() function. In C (and
acceptable in C++) there are FLT_EPSILON, DBL_EPSILON and
LDBL_EPSILON defined in <limits.h>. AFAIK, there is no function
in both C and C++ (C/C++ as you put it), but macros from <limits.h>
should be sufficient.

Victor
--
Please remove capital A's from my address when replying by mail


Steven Lord

unread,
Apr 3, 2002, 4:23:23 PM4/3/02
to

"Victor Bazarov" <vAba...@dAnai.com> wrote in message
news:d0Jq8.3776$Yb1....@sea-read.news.verio.net...

> "Joeri Verbiest" <joeri.v...@ieee.org> wrote...
> > I have a small question. In matlab we have eps to look what the floating
> > point relative accurancy is. Is there also a function in C/C++ for doing
> > this.
>
>
> In C++ there is std::numeric_limits<double>::epsilon() function
> and std::numeric_limits<float>::epsilon() function. In C (and
> acceptable in C++) there are FLT_EPSILON, DBL_EPSILON and
> LDBL_EPSILON defined in <limits.h>. AFAIK, there is no function
> in both C and C++ (C/C++ as you put it), but macros from <limits.h>
> should be sufficient.

Alternately, if you want to calculate it, Cleve described a quick
approximation technique in one of his Cleve's Corners:

http://www.mathworks.com/company/newsletter/pdf/Fall96Cleve.pdf

Execute the C/C++ equivalent of the code in the box on the first page; the
first full paragraph in the second column of the second page describes it.

--
Steve Lord
sl...@mathworks.com


one20...@yahoo.com

unread,
Apr 8, 2002, 9:12:10 PM4/8/02
to

Joeri Verbiest wrote:

I found
http://www.softintegration.com/products/features/ch_vs_matlab.html
might be useful for porting Matlab code to C/C++ or C like.
Porting eps in Matlab to DBL_EPSILON is lited as well.

The characteristic features of floating point numbers are
defined in header file float.h in C/C++.
esp in Matlab can be replaced by
DBL_EPSILON for double in C/C++.
In fact, C/C++ has FLT_EPSILON for float which is not available in Matlab.
However, I think Matlab might be able to convert Matlab code
to C/C++.

>
>
> Thanks
>
> Joeri

Lenin.Bhavanandan

unread,
Apr 15, 2002, 12:58:05 PM4/15/02
to
Hello there,

In Matlab, I have the following variables:

>> a = rand(3,2);
>> b = 0*a;

Normally one would expect 'b' to be 0 (singleton zero). But matlab produces
a zero matrix of size 3x2 for 'b'. Is there anyway to get rid of this problem?

Thanks and regards,
Lenin.

--
______________________________________________
Dr. R.B. Lenin
Department of Mathematics and Computer Science
University of Antwerp, Universiteitsplein 1
B-2610 Antwerp, Belgium
Tel: +32-3-8202416 Fax: +32-3-8202421
Email: le...@uia.ua.ac.be
Url: http://win-www.uia.ac.be/u/lenin/
______________________________________________


Donovan Rebbechi

unread,
Apr 15, 2002, 1:16:08 PM4/15/02
to
In article <3cbb069d$1...@news.uia.ac.be>, Lenin.Bhavanandan wrote:
> Hello there,
>
> In Matlab, I have the following variables:

Hello. Please do come back to comp.lang.c and comp.lang.c++ ... WHEN you have
questions about C or C++.

>>> a = rand(3,2);
>>> b = 0*a;
>
> Normally one would expect 'b' to be 0 (singleton zero).

One who understood elementary matrix operations would expect no such thing.

> Is there anyway to get rid of this problem?

The problem is your ignorance. To get rid of it, read a book about matrices,
and some FAQs about netiquette.

--
Donovan

Bob Hairgrove

unread,
Apr 15, 2002, 2:26:04 PM4/15/02
to
On 15 Apr 2002 18:58:05 +0200, le...@uia.ua.ac.be (Lenin.Bhavanandan)
wrote:

>Hello there,
>
>In Matlab, I have the following variables:
>
>>> a = rand(3,2);
>>> b = 0*a;
>
>Normally one would expect 'b' to be 0 (singleton zero). But matlab produces
>a zero matrix of size 3x2 for 'b'. Is there anyway to get rid of this problem?

As someone who never worked with matlab, I suppose I have no business
posting something here ... but it looks like you need a "." instead of
a "," between the 3 and the 2.

(BTW, what does this have to do with Standard C++ ?????)

Bob Hairgrove
rhairgro...@Pleasebigfoot.com

Ken Davis

unread,
Apr 15, 2002, 2:44:15 PM4/15/02
to
Why?

Ken

"Bob Hairgrove" <rhairgro...@Pleasebigfoot.com> wrote in message
news:3cbb1b43...@news.ch.kpnqwest.net...

Sean Eby

unread,
Apr 16, 2002, 12:10:43 AM4/16/02
to
"Lenin.Bhavanandan" <le...@uia.ua.ac.be> wrote in message
news:3cbb069d$1...@news.uia.ac.be...

My guess is he made a goof with his news reader. Something tells me he is
smarter than the matrix question he is asking about. We'll give him a break.

Sean


AJ "no z" Johnson

unread,
Apr 16, 2002, 5:18:12 AM4/16/02
to
Well, that wasn't exactly a stellar example of netiquette, was it?
-Aj

"Donovan Rebbechi" <elf...@panix.com> wrote in message
news:slrnabm2og....@panix2.panix.com...

Joona I Palaste

unread,
Apr 16, 2002, 5:59:57 AM4/16/02
to
"AJ \"no z\" Johnson" <aj.jo...@lmco.com> scribbled the following
on comp.lang.c:

> Well, that wasn't exactly a stellar example of netiquette, was it?
> -Aj

Was yours? You top-posted an unsnipped reply without adding any new
information.
BTW, can YOU spot Lenin's question about C and C++? I for one
certainly can't.

Also, how can anyone who has opened a basic textbook on linear algebra
think that 0*a, where a is a 3*2 matrix, will equal singleton zero?

> "Donovan Rebbechi" <elf...@panix.com> wrote in message
> news:slrnabm2og....@panix2.panix.com...
>> In article <3cbb069d$1...@news.uia.ac.be>, Lenin.Bhavanandan wrote:
>> > Hello there,
>> >
>> > In Matlab, I have the following variables:
>>
>> Hello. Please do come back to comp.lang.c and comp.lang.c++ ... WHEN you
> have
>> questions about C or C++.
>>
>> >>> a = rand(3,2);
>> >>> b = 0*a;
>> >
>> > Normally one would expect 'b' to be 0 (singleton zero).
>>
>> One who understood elementary matrix operations would expect no such
> thing.
>>
>> > Is there anyway to get rid of this problem?
>>
>> The problem is your ignorance. To get rid of it, read a book about
> matrices,
>> and some FAQs about netiquette.

--
/-- Joona Palaste (pal...@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"I will never display my bum in public again."
- Homer Simpson

AJ "no z" Johnson

unread,
Apr 16, 2002, 8:02:25 AM4/16/02
to
I find that I am subject to the same temptation to flame as anyone else. :-(
My intent was to point out that there are kinder ways to remind someone that
they inadvertently cross-posted to the incorrect forum(s). I left it
unsnipped so the context would be obvious.
I have answered the original appender's question in the newsgroup he
intended. The question was more about Matlab syntax than linear algebra.
-Aj

"Joona I Palaste" <pal...@cc.helsinki.fi> wrote in message
news:a9gsmt$gi4$1...@oravannahka.helsinki.fi...

Joona I Palaste

unread,
Apr 16, 2002, 10:11:01 AM4/16/02
to
"AJ \"no z\" Johnson" <aj.jo...@lmco.com> scribbled the following
on comp.lang.c:
> I find that I am subject to the same temptation to flame as anyone else. :-(
> My intent was to point out that there are kinder ways to remind someone that
> they inadvertently cross-posted to the incorrect forum(s). I left it
> unsnipped so the context would be obvious.
> I have answered the original appender's question in the newsgroup he
> intended. The question was more about Matlab syntax than linear algebra.
> -Aj

You're still top-posting, but otherwise I think you're OK.

> "Joona I Palaste" <pal...@cc.helsinki.fi> wrote in message
> news:a9gsmt$gi4$1...@oravannahka.helsinki.fi...
>> "AJ \"no z\" Johnson" <aj.jo...@lmco.com> scribbled the following
>> on comp.lang.c:
>> > Well, that wasn't exactly a stellar example of netiquette, was it?
>> > -Aj
>>
>> Was yours? You top-posted an unsnipped reply without adding any new
>> information.
>> BTW, can YOU spot Lenin's question about C and C++? I for one
>> certainly can't.
>>
>> Also, how can anyone who has opened a basic textbook on linear algebra
>> think that 0*a, where a is a 3*2 matrix, will equal singleton zero?

--

/-- Joona Palaste (pal...@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/

"Insanity is to be shared."
- Tailgunner

Default User

unread,
Apr 16, 2002, 1:10:30 PM4/16/02
to
Joona I Palaste wrote:

> You're still top-posting, but otherwise I think you're OK.

Ah, what can you expect from a Lock-Mart guy?

;)


Brian Rodenborn

Joona I Palaste

unread,
Apr 16, 2002, 1:29:08 PM4/16/02
to
Default User <first...@company.com> scribbled the following
on comp.lang.c:
> Joona I Palaste wrote:

>> You're still top-posting, but otherwise I think you're OK.

> Ah, what can you expect from a Lock-Mart guy?

> ;)

Huh? I don't understand this. Is it some kind of cultural thing?

--
/-- Joona Palaste (pal...@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/

"Stronger, no. More seductive, cunning, crunchier the Dark Side is."
- Mika P. Nieminen

Daniel Fox

unread,
Apr 16, 2002, 4:21:47 PM4/16/02
to
Joona I Palaste <pal...@cc.helsinki.fi> wrote in
news:a9hn14$b74$1...@oravannahka.helsinki.fi:

> Default User <first...@company.com> scribbled the following
> on comp.lang.c:
>> Joona I Palaste wrote:
>
>>> You're still top-posting, but otherwise I think you're OK.
>
>> Ah, what can you expect from a Lock-Mart guy?
>
>> ;)
>
> Huh? I don't understand this. Is it some kind of cultural thing?

It was a reference to Lockheed Martin, a very large defense contractor in
the USA. Note Mr. Johnson's mail address.

http://www.lockheedmartin.com/

I won't comment on why you would expect top-posting from a Lockheed Martin
employee; I'm not sure about that myself.

-Daniel

Default User

unread,
Apr 16, 2002, 4:18:41 PM4/16/02
to
Joona I Palaste wrote:

> > Ah, what can you expect from a Lock-Mart guy?
>
> > ;)
>
> Huh? I don't understand this. Is it some kind of cultural thing?

It's a US aerospace industry thing.


Brian Rodenborn

Mark McIntyre

unread,
Apr 16, 2002, 6:05:26 PM4/16/02
to
On Tue, 16 Apr 2002 20:21:47 GMT, Daniel Fox
<danielfox200...@hotmail.com> wrote:

>Joona I Palaste <pal...@cc.helsinki.fi> wrote in
>news:a9hn14$b74$1...@oravannahka.helsinki.fi:
>
>>

>> Huh? I don't understand this. Is it some kind of cultural thing?
>
>It was a reference to Lockheed Martin, a very large defense contractor in
>the USA. Note Mr. Johnson's mail address.
>
>http://www.lockheedmartin.com/
>
>I won't comment on why you would expect top-posting from a Lockheed Martin
>employee; I'm not sure about that myself.

Brian probably works for a competitor. If I saw a posting from someone
daft enough to admit to working at SocGen I'd probably be equally
disparaging in a friendly sort of way. After all, its not /their/
fault, they just needed the money.... :->
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>

Default User

unread,
Apr 16, 2002, 7:02:15 PM4/16/02
to
Mark McIntyre wrote:

> >I won't comment on why you would expect top-posting from a Lockheed Martin
> >employee; I'm not sure about that myself.
>
> Brian probably works for a competitor. If I saw a posting from someone
> daft enough to admit to working at SocGen I'd probably be equally
> disparaging in a friendly sort of way. After all, its not /their/
> fault, they just needed the money.... :->

Zactly.

Brian Rodenborn

AJ "no z" Johnson

unread,
Apr 17, 2002, 6:06:23 AM4/17/02
to
"Joona I Palaste" <pal...@cc.helsinki.fi> wrote in message
news:a9hbdl$m2$1...@oravannahka.helsinki.fi...

>
> You're still top-posting, but otherwise I think you're OK.
>

OK, I'll be a team-player. (What do you want - I'm using Microsoft
newsreader!)
-Aj

"A man who thinks he is wise is not."


0 new messages