taitai
taitai

Reputation: 21

what is a good way to change unsigned minus unsigned to be signed?

I just found unsigned minus unsigned is quite strange when you have a negative number. For example,

unsigned a = 2;
unsigned b = 0;
unsigned c = 1;
unsigned d = 3;
unsigned e = 4;
unsigned f = 0;
double ans = (a-b)*(c-d)/(e-f);

ans will not be the value you expect. What is a good way to define ans?

if I do double ans = (double)(a-b)*(c-d)/(e-f), it is not correct either.

Upvotes: 0

Views: 101

Answers (0)

Related Questions