You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
srand(42);
my $time = DateTime.new(1534447684).utc + Duration.new(0.002);
for ^100 -> $i {
$time = $time + Duration.new(2.rand);
say "$i $time";
}
gives me:
0 2018-08-16T19:28:04.551037Z
1 2018-08-16T19:28:05.684497Z
2 2018-08-16T19:28:07.604283Z
3 2018-08-16T19:28:07.911050Z
4 2018-08-16T19:28:09.078071Z
5 2018-08-16T19:28:09.513809Z
Type check failed in assignment to $!tai; expected Rat but got Num (1534447727.7935638e0)
in block <unit> at ./golf line 7
my perl is 2018.04.1-33-ga957b712c built on MoarVM version 2018.04-39-gc702f4c66
The text was updated successfully, but these errors were encountered:
And what's happening here is the addition actually produces such a Rat, and we end up with an attempt to assign a Num into a Rat attribute (the $.tai).
One possible fix would be to use Rat.new with the summed up numerators denominators, because Rat.new allows "overloaded" denominators that are larger than 64 bits and it won't degrade to a Num. However, we still end up with .tai that contains a Rat that'd degrade to a Num in math operators, so perhaps that's a bad idea.
The other fix would be to have all the .tai operations coerce to a .Rat, so we force the Num back to a Rat, but that's losing some precision due to this roundtrip.
Haven't thought about this much, so there might be much better solutions available.
don't quite understand what is going on, but:
gives me:
my perl is 2018.04.1-33-ga957b712c built on MoarVM version 2018.04-39-gc702f4c66
The text was updated successfully, but these errors were encountered: