Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl6 Function floor works differently with numbers and strings?

Quick question:

-1.9.floor gives you -1, while "-1.9".floor gives you -2. Is it supposed to be so? Seems a bit inconsistent to me.

> say -1.9.floor
-1
> say "-1.9".floor
-2

Documentation says "rounds it downwards to the nearest integer". Should both be -2?

Thanks!!!

like image 361
lisprogtor Avatar asked Mar 24 '19 19:03

lisprogtor


1 Answers

Seems to be some operator precedence. Make the number a variable and use floor on the variable it looks ok.

my $i = -1.9;
say $i.floor; #-2 

I your example it makes: .9.floor ==> 0 and then -1.0 ==> -1

like image 138
LuVa Avatar answered Sep 20 '22 00:09

LuVa