خرید بک لینک

Vote count: 0

I have old pascal code

var i : longint;
    m : double;
begin
  .....
  i := trunc(m);

I have to convert it to C++ code.

An obvious thing here is to write

double m;
int i;
.....
i = static_cast<int>(std::trunc(m));

But the problem here is than pascal's trunc retus integer

function trunc(
  d: ValReal
):Int64;

while c++'s trunc retus double. Is it possible that for example trunc(2.3) will retu 1.999999999999 and static_cast will make it 1 instead of 2? If yes is it correct to use static_cast without trunc to get same pascal's behavior?

i = static_cast<int>(m);

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 4 خرداد 1395 ساعت: 21:09

صفحه بندی