help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Issues with glp_get_col_prim


From: Andrew Makhorin
Subject: Re: [Help-glpk] Issues with glp_get_col_prim
Date: Sat, 30 Aug 2008 21:15:52 +0400

> Im storing the value that glp_get_col_prim into a int by making a
> cast, but sometimes it doesnt work.

> Im printin the value of glp_get_col_prim and theres times when its
> 1.0000 (that means a 1 in double) and I make the cast to int, the cast
> stores a 0 instead of a 1.

On printing floating-point values printf performs appropriate rounding,
for example, 0.99999999231 being printed with 6 decimal places looks
like 1.00000 . Most probably the value reported by glp_get_col_prim is
a bit (i.e. within a tolerance) less than 1, so on printing it you see 1
while on casting it to int you get 0, because converting double to int
assumes rounding toward zero. To get correctly rounded result you should
write (int)(x + 0.5) rather than (int)(x).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]