[OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

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

[OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
 

Hi, I found this why implementing a binary protocol - negative numbers are encoded in the same way as positive:

10 asByteArray = (-10 asByteArray) .  " => true"

While (usually) that's not the case and bitString shows it as well:

10 bitString = (-10 bitString ).  " => false"

I suggest that -10 asByteArray result is same as bitstring represented in bytes, as well as asByteArrayOfSize:.

What do you think?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"Incomplete implementation of `asByteArray` for negative numbers? (#324)"}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
 

The solution can be like this for asByteArrayOfSize: and asByteArray is pretty similar:

negative := self negative.
negative 
	ifTrue: [
		number := self + 1.
		answer := ByteArray new: aSize withAll: 255 ]
	ifFalse: [
                number := self.
		answer := ByteArray new: aSize. ].

digitPos := 1.
aSize 
	to: aSize - number digitLength + 1
	by: -1
	do: 
		[ :pos | 
		answer 
			at: pos
			put: (
				negative 
					ifTrue: [ 255 - (number digitAt: digitPos) ]
					ifFalse: [ number digitAt: digitPos ]
			).
		digitPos := digitPos + 1 ].
^ answer.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@maximvl in #324: The solution can be like this for `asByteArrayOfSize:` and `asByteArray` is pretty similar:\r\n```\r\nnegative := self negative.\r\nnegative \r\n\tifTrue: [\r\n\t\tnumber := self + 1.\r\n\t\tanswer := ByteArray new: aSize withAll: 255 ]\r\n\tifFalse: [\r\n number := self.\r\n\t\tanswer := ByteArray new: aSize. ].\r\n\r\ndigitPos := 1.\r\naSize \r\n\tto: aSize - number digitLength + 1\r\n\tby: -1\r\n\tdo: \r\n\t\t[ :pos | \r\n\t\tanswer \r\n\t\t\tat: pos\r\n\t\t\tput: (\r\n\t\t\t\tnegative \r\n\t\t\t\t\tifTrue: [ 255 - (number digitAt: digitPos) ]\r\n\t\t\t\t\tifFalse: [ number digitAt: digitPos ]\r\n\t\t\t).\r\n\t\tdigitPos := digitPos + 1 ].\r\n^ answer.\r\n```"}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632285"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632285", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632285", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
In reply to this post by David T Lewis
 

Also asInteger of ByteArray should be changed accordingly to support negative numbers.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@maximvl in #324: Also `asInteger` of ByteArray should be changed accordingly to support negative numbers."}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632719"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632719", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448632719", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
In reply to this post by David T Lewis
 

These methods only exist in one fork using the VM, and they are all unrelated to the VM itself.
You might want to close this issue and open another one on the fork's issue tracker.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@smalltalking in #324: These methods only exist in one fork using the VM, and they are all unrelated to the VM itself.\r\nYou might want to close this issue and open another one on the fork's issue tracker."}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448654094"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448654094", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448654094", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
In reply to this post by David T Lewis
 

Which fork is that?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@bencoman in #324: Which fork is that?"}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448727119"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448727119", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448727119", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
In reply to this post by David T Lewis
 

Pharo. But it's totally irrelevant, as this is repository is for the VM.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@smalltalking in #324: Pharo. But it's totally irrelevant, as this is repository is for the VM."}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448775932"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448775932", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448775932", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
In reply to this post by David T Lewis
 

@smalltalking Oh sorry, the Pharo project does not support issues on github, I thought I should put it here.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@maximvl in #324: @smalltalking Oh sorry, the Pharo project does not support issues on github, I thought I should put it here."}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448910837"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448910837", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448910837", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
In reply to this post by David T Lewis
 

Closed #324.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"Closed #324."}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#event-2037711301"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#event-2037711301", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#event-2037711301", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] Incomplete implementation of `asByteArray` for negative numbers? (#324)

David T Lewis
In reply to this post by David T Lewis
 

@maximvl, Go to pharo.fogbugz.com


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@bencoman in #324: @maximvl, Go to [pharo.fogbugz.com](https://pharo.fogbugz.com)"}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448926349"}}}</script> <script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448926349", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/324#issuecomment-448926349", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>