Error in ByteArray>>booleanAt:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Error in ByteArray>>booleanAt:

raffaello.giulietti
Hi,

the current (Pharo 6) code reads

^(self integerAt: byteOffset size: 1 signed: false) == true

so it always returns false, as no integer is identical to true.


Instead, it should read

^(self integerAt: byteOffset size: 1 signed: false) ~= 0

implementing the usual convention that 0 maps to false and every other
value maps to true.

Greetings
Raffaello

Reply | Threaded
Open this post in threaded view
|

Re: Error in ByteArray>>booleanAt:

Sven Van Caekenberghe-2

> On 22 Jun 2017, at 17:39, Raffaello Giulietti <[hidden email]> wrote:
>
> Hi,
>
> the current (Pharo 6) code reads
>
> ^(self integerAt: byteOffset size: 1 signed: false) == true
>
> so it always returns false, as no integer is identical to true.
>
>
> Instead, it should read
>
> ^(self integerAt: byteOffset size: 1 signed: false) ~= 0
>
> implementing the usual convention that 0 maps to false and every other value maps to true.
>
> Greetings
> Raffaello

Good catch, probably a typo.

IMO, there should have been unit tests to validate such code.



Reply | Threaded
Open this post in threaded view
|

Re: Error in ByteArray>>booleanAt:

Pavel Krivanek-3
In reply to this post by raffaello.giulietti

2017-06-22 17:39 GMT+02:00 Raffaello Giulietti <[hidden email]>:
Hi,

the current (Pharo 6) code reads

^(self integerAt: byteOffset size: 1 signed: false) == true

so it always returns false, as no integer is identical to true.


Instead, it should read

^(self integerAt: byteOffset size: 1 signed: false) ~= 0

implementing the usual convention that 0 maps to false and every other value maps to true.

Greetings
Raffaello


Reply | Threaded
Open this post in threaded view
|

Re: Error in ByteArray>>booleanAt:

Eliot Miranda-2


On Fri, Jun 23, 2017 at 4:19 AM, Pavel Krivanek <[hidden email]> wrote:

Fixed in 
Name: FFI-Kernel-eem.46
Author: eem
Time: 23 June 2017, 10:00:42.756292 am
UUID: ab2b7c9e-0edb-4f10-8fd2-32400997fb8e
Ancestors: FFI-Kernel-EstebanLorenzano.45

Fix booleanAt:

(This is part of the FFI package)
 


2017-06-22 17:39 GMT+02:00 Raffaello Giulietti <[hidden email]>:
Hi,

the current (Pharo 6) code reads

^(self integerAt: byteOffset size: 1 signed: false) == true

so it always returns false, as no integer is identical to true.


Instead, it should read

^(self integerAt: byteOffset size: 1 signed: false) ~= 0

implementing the usual convention that 0 maps to false and every other value maps to true.

Greetings
Raffaello





--
_,,,^..^,,,_
best, Eliot