in reply to Behaviour of int() unexpected

2˘:

#!/usr/bin/env perl use strict; use warnings; use feature qw(say); use Math::Round; say 8.95 * 100; printf("%.15f\n", 8.95 * 100); printf("%f\n", 8.95 * 100); printf("%d\n", 8.95 * 100); printf("%d\n", round(8.95 * 100)); say int(8.95 * 100); say int(round(8.95 * 100)); __END__
karl@rantanplan:~/src/cpp/acme$ ./meditation.pl 895 894.999999999999886 895.000000 894 895 894 895
#include <iomanip> #include <iostream> #include <cmath> using std::cout; using std::round; int main() { double a = 8.95; double b = 100; double r = a * b; cout.precision(18); cout << r << " - precision 18\n"; cout << int(r) << " - int \n"; cout << round(r) << " - round\n"; cout.precision(6); cout << r << " - precision 6\n"; cout << "Supernatural!\n"; return 1; }
karl@rantanplan:~/src/cpp/acme$ clang++-18 -std=c++23 meditation.cpp - +o meditation karl@rantanplan:~/src/cpp/acme$ ./meditation 894.999999999999886 - precision 18 894 - int 895 - round 895 - precision 6 Supernatural!

perlnumber