Why does (5/3) not equal (5/3)?

Joined
Jan 11, 2023
Messages
9
Reaction score
0
Code:
int highest = 5;
int lowest = 3;
std::cout << "((float)highest/(float)lowest) = " << ((float)highest/(float)lowest) << "\n";
std::cout << "(5.0/3.0) = " << (5.0/3.0) << "\n";
std::cout << "(((float)highest/(float)lowest) == (5.0/3.0)) = "
<< (((float)highest/(float)lowest) == (5.0/3.0)) << "\n";

output:

Code:
((float)highest/(float)lowest) = 1.66667
(5.0/3.0) = 1.66667
(((float)highest/(float)lowest) == (5.0/3.0)) = 0

why does (5/3) not equal (5/3)?
 
Joined
Jan 11, 2023
Messages
2
Reaction score
1
Code:
int highest = 5;
int lowest = 3;
std::cout << "((float)highest/(float)lowest) = " << ((float)highest/(float)lowest) << "\n";
std::cout << "(5.0/3.0) = " << (5.0/3.0) << "\n";
std::cout << "(((float)highest/(float)lowest) == (5.0/3.0)) = "
<< (((float)highest/(float)lowest) == (5.0/3.0)) << "\n";

output:

Code:
((float)highest/(float)lowest) = 1.66667
(5.0/3.0) = 1.66667
(((float)highest/(float)lowest) == (5.0/3.0)) = 0

why does (5/3) not equal (5/3)?
Round off error; (5.0/3.0) is a double, not a float
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top