Yes, but it would be good to have a reversible PRNG available in software for programming, where you want to be able to seed it, in order to get a repeatable pattern. Reversibility is nice, too. This could just be an LFSR, or something better, working on a long variable.
The hardware PRNG is the Xoroshiro128+ and that thing might as well be a TRNG.
Chip, you are missing the sign extend operators. Unless I am just blind? Also, I think keeping the aliases is perfectly fine.
jmg, in C >> is implementation defined, but every compiler I have ever used has it as an arithmetic shift. And Chip has it has arithmetic. He could add the SAR alias to it.
Also, << is always not arithmetic (being non-sign preserving).
Chip, you are missing the sign extend operators. Unless I am just blind? Also, I think keeping the aliases is perfectly fine.
jmg, in C >> is implementation defined, but every compiler I have ever used has it as an arithmetic shift. Also, << is always not arithmetic (being non-sign preserving).
There is now EXTS, which is a general case, where you supply the bit number to extend from.
We could call it SEXT, which is more natural, but awfully distracting. EXTS looks like "extension?!?".
LOG and EXP are base-2, what would you suggest? LOG2 and EXP2, maybe?
Hmm, if they are not Natural, or base 10, it would pay to avoid those names, to allow user functions to user those names.
If they work base2, then LOG2, EXP2 seems ok
addit:
Yes, Google finds instances of LOG2 and EXP2 that do what they suggest.
Right Shifts
The right-shift operator causes the bit pattern in shift-expression to be shifted to the right by the number of positions specified by additive-expression. For unsigned numbers, the bit positions that have been vacated by the shift operation are zero-filled. For signed numbers, the sign bit is used to fill the vacated bit positions. In other words, if the number is positive, 0 is used, and if the number is negative, 1 is used. Important :
The result of a right-shift of a signed negative number is implementation-dependent. Although Visual C++ uses the sign bit to fill vacated bit positions, there is no guarantee that other implementations also do so.
ugh.
Sounds like SHR and SAR are the needed aliases to give predictable outcomes.
ie if someone tries to port >> that used the 'other convention', there is a way to get the expected result.
LOG and EXP are base-2, what would you suggest? LOG2 and EXP2, maybe?
Hmm, if they are not Natural, or base 10, it would pay to avoid those names, to allow user functions to user those names.
If they work base2, then LOG2, EXP2 seems ok
addit:
Yes, Google finds instances of LOG2 and EXP2 that do what they suggest.
Right Shifts
The right-shift operator causes the bit pattern in shift-expression to be shifted to the right by the number of positions specified by additive-expression. For unsigned numbers, the bit positions that have been vacated by the shift operation are zero-filled. For signed numbers, the sign bit is used to fill the vacated bit positions. In other words, if the number is positive, 0 is used, and if the number is negative, 1 is used. Important :
The result of a right-shift of a signed negative number is implementation-dependent. Although Visual C++ uses the sign bit to fill vacated bit positions, there is no guarantee that other implementations also do so.
ugh.
Sounds like SHR and SAR are the needed aliases to give predictable outcomes.
ie if someone tries to port >> that used the 'other convention', there is a way to get the expected result.
Both. They're two different operators. Both are lazy: i.e. if they fail partway through, the rest of the expression is not evaluated. AND has lower precedence than &&, helping to reduce the need for parens.
Same with || and OR. Both are lazy operators. They stop evaluating upon the first TRUE result. OR has lower precedence than ||.
Just keep !; forget NOT, same with << and >>. Self-explanatory.
^ and XOR are two separate operators: ^ is bitwise; XOR is Boolean. Both are useful. If you wanted to, you could add ^^ as an analog of && and ||.
Regarding >= and =>, just make up your mind, and pick one! An alias there just confuses things further.
Signed shifts and rotates: keep what you had in Spin 1.
IOW, forget aliases altogether. Pick the most C-like of each pair and jettison the other.
Phil, AND and && are the same, not sure why you think they are different. Same with || and OR.
& is different from && and AND, just like | is from || and OR
Not sure I like all those aliases. I can see the "gurus" using the cryptic symbols thus confusing the newbies trying to read their code. I rather all the C operators were C style cryptic symbols and the other Spin specific operators as textual acronyms only.
It make sense to use C style operator precedence if you are using C style operators.
I dislike (actually hate) the cryptic symbols of both C and spin.
That is why it has been said that C was invented by programmers who were scared of losing their jobs, so they made C able to be as obtuse as possible.
And by this, I don't mean the simple things like
x := (a+b)*(c+d)
x++
but I do mean things like
x <= 5
and long convoluted expressions where precedence is used, rather than using parenthesis to ensure correct interpretation (not the simple * / + - which everyone should know).
Why do you imagine that ?
Surely a true Guru recognizes the audience, and creates the clearest code, where they know newbies will be reading.
I know what you mean.
But how does a guru know who is audience is? He writes his code, he sticks in in OBEX or github etc. Every newbie in the world get's to read it. Which is almost everybody as very few people know Spin.
I can also imagine source emerging that is a soup of cryptic operators and acronyms all mixed up in a blinding mess!
Having cryptic symbols and acronyms is just more junk someone has to learn.
I'd go with &&. If we are going to have C style we should have C style.
! NOT
&& AND
|| OR
^ XOR
<< SHL
% MOD
[b]=< <=
=> >=[/b]
<> !=
Looks good.
As minor suggestion:
- I will remove the aliases for equality operators (greater or equal and less or equal) and
- add the OR and AND alias also for | and & if the compiler can understand how to discriminate between boolean and bitwise.
Why do you imagine that ?
Surely a true Guru recognizes the audience, and creates the clearest code, where they know newbies will be reading.
I know what you mean.
But how does a guru know who is audience is? He writes his code, he sticks in in OBEX or github etc. Every newbie in the world get's to read it. Which is almost everybody as very few people know Spin.
I can also imagine source emerging that is a soup of cryptic operators and acronyms all mixed up in a blinding mess!
Having cryptic symbols and acronyms is just more junk someone has to learn.
I'd go with &&. If we are going to have C style we should have C style.
Comments
Yes, but it would be good to have a reversible PRNG available in software for programming, where you want to be able to seed it, in order to get a repeatable pattern. Reversibility is nice, too. This could just be an LFSR, or something better, working on a long variable.
The hardware PRNG is the Xoroshiro128+ and that thing might as well be a TRNG.
Me neither.
The next big thing we'll have to work out is precedence.
jmg, in C >> is implementation defined, but every compiler I have ever used has it as an arithmetic shift. And Chip has it has arithmetic. He could add the SAR alias to it.
Also, << is always not arithmetic (being non-sign preserving).
There is now EXTS, which is a general case, where you supply the bit number to extend from.
We could call it SEXT, which is more natural, but awfully distracting. EXTS looks like "extension?!?".
SIGNX, maybe?
I though of SIGNEXT, too, but it reads like "signal next".
I'll change it to SIGNX.
EXTB 'sign extend byte
EXTW Sign extend word
If they work base2, then LOG2, EXP2 seems ok
addit:
Yes, Google finds instances of LOG2 and EXP2 that do what they suggest.
This link suggests >> shifts in 0 for C ?
http://www.c4learn.com/c-programming/c-bitwise-right-shift/
but then this gets murkier
https://msdn.microsoft.com/en-us/library/336xbhcz.aspx
Right Shifts
The right-shift operator causes the bit pattern in shift-expression to be shifted to the right by the number of positions specified by additive-expression. For unsigned numbers, the bit positions that have been vacated by the shift operation are zero-filled. For signed numbers, the sign bit is used to fill the vacated bit positions. In other words, if the number is positive, 0 is used, and if the number is negative, 1 is used.
Important :
The result of a right-shift of a signed negative number is implementation-dependent. Although Visual C++ uses the sign bit to fill vacated bit positions, there is no guarantee that other implementations also do so.
ugh.
Sounds like SHR and SAR are the needed aliases to give predictable outcomes.
ie if someone tries to port >> that used the 'other convention', there is a way to get the expected result.
Those would be special cases, but we could do that.
Good point, I just added an alias, SAR, to >>.
Chip, SIGNX works well enough. I don't think we need extb or extw, signx can do those plus any other size.
Done.
Same with || and OR. Both are lazy operators. They stop evaluating upon the first TRUE result. OR has lower precedence than ||.
Just keep !; forget NOT, same with << and >>. Self-explanatory.
^ and XOR are two separate operators: ^ is bitwise; XOR is Boolean. Both are useful. If you wanted to, you could add ^^ as an analog of && and ||.
Regarding >= and =>, just make up your mind, and pick one! An alias there just confuses things further.
Signed shifts and rotates: keep what you had in Spin 1.
IOW, forget aliases altogether. Pick the most C-like of each pair and jettison the other.
Thanks,
-Phil
& is different from && and AND, just like | is from || and OR
Seconded. Me too
SIGNX sounds good, or maybe SIGNEX, or is that still too close to signal next ?
I would like NOT to have a low precedence, so it's useful with AND and OR, without needing parentheses.
It make sense to use C style operator precedence if you are using C style operators.
Why do you imagine that ?
Surely a true Guru recognizes the audience, and creates the clearest code, where they know newbies will be reading.
That is why it has been said that C was invented by programmers who were scared of losing their jobs, so they made C able to be as obtuse as possible.
And by this, I don't mean the simple things like
x := (a+b)*(c+d)
x++
but I do mean things like
x <= 5
and long convoluted expressions where precedence is used, rather than using parenthesis to ensure correct interpretation (not the simple * / + - which everyone should know).
Just MHO.
But how does a guru know who is audience is? He writes his code, he sticks in in OBEX or github etc. Every newbie in the world get's to read it. Which is almost everybody as very few people know Spin.
I can also imagine source emerging that is a soup of cryptic operators and acronyms all mixed up in a blinding mess!
Having cryptic symbols and acronyms is just more junk someone has to learn.
I'd go with &&. If we are going to have C style we should have C style.
As minor suggestion:
- I will remove the aliases for equality operators (greater or equal and less or equal) and
- add the OR and AND alias also for | and & if the compiler can understand how to discriminate between boolean and bitwise.
What about SGNEX for sign extension?
I am glad though that <= and >= are no longer assignment operators.