Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shaped arrays with fractional sizes (my @a[0.5]) #4817

Open
p6rt opened this issue Dec 4, 2015 · 2 comments
Open

Shaped arrays with fractional sizes (my @a[0.5]) #4817

p6rt opened this issue Dec 4, 2015 · 2 comments
Labels
lhf

Comments

@p6rt
Copy link

@p6rt p6rt commented Dec 4, 2015

Migrated from rt.perl.org#126802 (status was 'new')

Searchable as RT126802$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Dec 4, 2015

From @AlexDaniel

My previous bug report was about overflow associated with negative sizes
(RT #​126800)

This time it is a little bit different​:
my @​a[0.5]; say @​a.perl;

Result​:
Index 0 for dimension 1 out of range (must be 0..-1)
  in block <unit> at -e​:1

Actually, it only accepts values that can unbox to a native integer. “0.5”
is not an integer, so perhaps it should fail earlier?

That being said, I think sometimes it could be useful to create an array if
you have a num value without rounding it down first. So maybe it should not
be forbidden, but then it should not be buggy.

Interestingly, it is not only about “-1” sneaking in​:
my @​a[5.5]; say @​a.perl

Result​:
Index 5 for dimension 1 out of range (must be 0..4)
  in block <unit> at -e​:1

Perhaps it should just round it down to an integer internally? … but why
not up?

<AlexDaniel> TimToady​: “my @​a[5.5]” – what should it mean? [5], [6] or
error?
<TimToady> AlexDaniel​: I think an error would be appropriate if .narrow
doesn't get an Int
<TimToady> since a dynamic 5.5 might well indicate that you need 6, but
maybe not
<TimToady> and we should force them to put ceiling if they mean that

Well, hmm… Go figure!

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Oct 5, 2017

From @AlexDaniel

The first part of the ticket was resolved in rakudo/rakudo@46dca95

So you can no longer create an array using 0.5.

But you can still create an array with any fractional value that's larger than 1, and it will blow up later.

♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
For SQUASHathoners​:
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥

The commit mentioned above gives a clue on what part of the code can be changed to resolve the issue. https://github.com/rakudo/rakudo/blob/cef3bf3e75411a5a664f93ea72209637eaaf5e3d/src/core/Rakudo/Internals.pm#L357-L362

I *think* that calling .Int on it will resolve the issue, but this of course won't produce a Failure which was recommended by TimToady. Either way the issue should be easy to approach.

On 2015-12-03 19​:32​:19, alex.jakimenko@​gmail.com wrote​:

My previous bug report was about overflow associated with negative sizes
(RT #​126800)

This time it is a little bit different​:
my @​a[0.5]; say @​a.perl;

Result​:
Index 0 for dimension 1 out of range (must be 0..-1)
in block <unit> at -e​:1

Actually, it only accepts values that can unbox to a native integer. “0.5”
is not an integer, so perhaps it should fail earlier?

That being said, I think sometimes it could be useful to create an array if
you have a num value without rounding it down first. So maybe it should not
be forbidden, but then it should not be buggy.

Interestingly, it is not only about “-1” sneaking in​:
my @​a[5.5]; say @​a.perl

Result​:
Index 5 for dimension 1 out of range (must be 0..4)
in block <unit> at -e​:1

Perhaps it should just round it down to an integer internally? … but why
not up?

<AlexDaniel> TimToady​: “my @​a[5.5]” – what should it mean? [5], [6] or
error?
<TimToady> AlexDaniel​: I think an error would be appropriate if .narrow
doesn't get an Int
<TimToady> since a dynamic 5.5 might well indicate that you need 6, but
maybe not
<TimToady> and we should force them to put ceiling if they mean that

Well, hmm… Go figure!

@p6rt p6rt added the lhf label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.