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

unsigned right-bit shift operator #2612

Open
ldci opened this issue Jul 21, 2024 · 3 comments
Open

unsigned right-bit shift operator #2612

ldci opened this issue Jul 21, 2024 · 3 comments

Comments

@ldci
Copy link

ldci commented Jul 21, 2024

Could it be possible to add >>> operator (unsigned right-bit shift) ?

; >>> operator not supported by r3
bin: to integer! #{45444571}
print bin
sign: bin >>> 31
expo: bin << 1 >>> 24
mant: bin << 9 >>> 9
print (pick [1 -1] 1 + sign) * (2 ** (expo - 127)) * (mant / (2 ** 23) + 1)
@Oldes
Copy link
Owner

Oldes commented Jul 21, 2024

It looks that there is difference between R3 and Red.
In Red:

> ? "shift"
     <<              op!           Shift bits to the left.
     >>              op!           Shift bits to the right.
     >>>             op!           Shift bits to the right (unsigned).
     shift           native!       Perform a bit shift operation. Right shift (decreasing) by default.
     shift-left      routine!      Shift bits to the left.
     shift-logical   routine!      Shift bits to the right (unsigned).
     shift-right     routine!      Shift bits to the right.

While in Rebol:

>> ? "shift"
Found these related matches:
  shift           native!    Shifts an integer left or right by a number of bits.
  shift-left      native!    Shift bits to the left (unsigned).
  shift-right     native!    Shift bits to the right (unsigned).
  <<              op!        Shift bits to the left (unsigned).
  >>              op!        Shift bits to the right (unsigned).

So in Rebol >> is now equal to Red's >>>.

But you should not expect same result in Rebol like in Red, because Red has 32bit integers, while Rebol3 has them 64bit!

@ldci
Copy link
Author

ldci commented Jul 21, 2024

Thanks for this immediate response. The more I use your Rebol R3, the more I like it.

@Oldes
Copy link
Owner

Oldes commented Jul 21, 2024

In Rebol3 you can use this instead:

>> binary/read #{45444571} 'F32BE
== 3140.34008789062

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants