[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: [OFFTOPIC] std::numeric_limits<double>::min() question.
From: "Will Entriken" <kde.org () 2006 ! phor ! net>
Date: 2006-04-26 20:12:43
Message-ID: c0be00e90604261312r562e0e4etbb8661053b41955 () mail ! gmail ! com
[Download RAW message or body]
std::numeric_limits<double>::min() return the minimum positive value.
you could try maxd = -1 if d will be non-negative. that will be pretty
obvious what is going on.
Cheers,
Will
On 4/26/06, Dmitry Suzdalev <dimsuz@gmail.com> wrote:
> Hello!
>
> Please, sorry for offtopic, I write here in hope that this question will be
> quickly answered as it seems to be simple (and I lack some knowledge).
>
> I have a C++ code like this:
>
> double d = 0;
> double maxd = std::numeric_limits<double>::min();
> ....
> while(...)
> {
> d = ....;
> if( d > maxd)
> {
> maxd = d;
> .....
> }
> }
>
> I.e., i want 'if' to _always_ evaluate to true on _first_ iteration.
> But it doesn't work!
> Gdb shows me that after initialisation 'maxd' is a _positive_ (and of course
> huge) value!
> Isn't it meant to be negative (despite of how it's internally stored in
> "internals")? :)
>
> Note, that if I change the second line to
>
> double maxd = - std::numeric_limits<double>::max();
>
> then all works as I expect!
> But I'd rather do without such tricks and write the code that's straitforward
> and less messy ;).
>
> What am I getting wrong?
> Thanks in advance! :)
>
> Dmitry.
>
> >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
>
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic