Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
fix working with double
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-cat-tty committed Nov 9, 2021
1 parent 04e7367 commit 738197b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions esercitazioni/funzioni_reali.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <iostream>
#include <cmath>
#include <limits>

using namespace std;

Expand Down Expand Up @@ -28,7 +29,7 @@ double val_assoluto(double n) {
}

double arrotonda_per_eccesso(double n) {
if (val_assoluto(n)-static_cast<int>(val_assoluto(n)) == 0)
if (val_assoluto(n)-static_cast<int>(val_assoluto(n)) < numeric_limits<double>::epsilon())
return n;

return n > 0. ?
Expand All @@ -37,7 +38,7 @@ double arrotonda_per_eccesso(double n) {
}

double arrotonda_per_difetto(double n) {
if (val_assoluto(n)-static_cast<int>(val_assoluto(n)) == 0)
if (val_assoluto(n)-static_cast<int>(val_assoluto(n)) < numeric_limits<double>::epsilon())
return n;

return n > 0. ?
Expand Down

0 comments on commit 738197b

Please sign in to comment.