Add rounding in float constructor
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 17 Oct 2024 11:54:58 +0000 (13:54 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 17 Oct 2024 11:54:58 +0000 (13:54 +0200)
ex01/Fixed.cpp

index 8f5ceb4eea333c8a3f06ff14caf2c15ad7e74c2d..ce732a8c88ccbfdbe0a01fb8892ee3b9515ac79e 100644 (file)
@@ -1,4 +1,5 @@
 #include "Fixed.h"
+#include <cmath>
 #include <iostream>
 
 Fixed::Fixed(): m_num(0)
@@ -10,7 +11,7 @@ Fixed::Fixed(const int init): m_num(init << point_pos)
 {
        std::cout << "Int constructor called\n";
 }
-Fixed::Fixed(const float init): m_num(init * (1 << point_pos))
+Fixed::Fixed(const float init): m_num(roundf(init * (1 << point_pos)))
 {
        std::cout << "Float constructor called\n";
 }