From 44f763d99b96e8bb239803414957fdf770c5ff88 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Thu, 17 Oct 2024 13:54:58 +0200 Subject: [PATCH] Add rounding in float constructor --- ex01/Fixed.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ex01/Fixed.cpp b/ex01/Fixed.cpp index 8f5ceb4..ce732a8 100644 --- a/ex01/Fixed.cpp +++ b/ex01/Fixed.cpp @@ -1,4 +1,5 @@ #include "Fixed.h" +#include #include 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"; } -- 2.30.2