Coder Social home page Coder Social logo

LSL same as ASH about oberon HOT 11 CLOSED

rochus-keller avatar rochus-keller commented on July 29, 2024
LSL same as ASH

from oberon.

Comments (11)

rochus-keller avatar rochus-keller commented on July 29, 2024

LSL is not the same as ASH. ASH was a built-in function in Oberon 90 and Oberon-2. It was replaced in Oberon-07 by LSL and ASR. LSL is a logical left shift and ASR an arithmetic right shift. The system module function ROT of Oberon 90 and Oberon-07 was renamed to ROR for right rotation. Even if the type of n is INTEGER in the Oberon-07 specification, I don't think that negative n make sense (i.e. would contradict the fact that the generic ASH was replaced by explicit left and right shift functions). But that's just an assumption, since the language report is not particularly specific. ROR is currently implemented as a simple unsigned shift operation, not a true rotation.

from oberon.

tenko avatar tenko commented on July 29, 2024

I am not sure what is correct here.

In mathematics, raise to negative whole number become division and raise to zero is defined as one (which in this case does not make sense)

It seems some Oberon-2 code rely on negative argument : https://github.com/Oleg-N-Cher/OfrontPlus/blob/master/Mod/Lib/MathL.cp

If only positive argument is allowed then the value should probably be clamped to positive to avoid the large negative value in the example.

from oberon.

rochus-keller avatar rochus-keller commented on July 29, 2024

Don't mix up Oberon-2 and before which only had the ASH feature and also had to accept negative n. Oberon-07 is a different case. By the end of the day we just have to define the features which I will specify and implement in Oberon+. I even consider re-adding ASH for backward compatibility. The Component Pascal platform specific issue report (in contrast to all Oberon language reports) is at least explicit for ROT with "(n > 0: left, n < 0: right)".

from oberon.

tenko avatar tenko commented on July 29, 2024

Thanks for the clarification. I will wait until this is implemented.

from oberon.

rochus-keller avatar rochus-keller commented on July 29, 2024

I pushed a commit to Github for IDE 0.9.40 which implements a couple of preliminary specification changes;

for one part all BITxyz operations now accept both INTEGER and LONGINT and the result is LONGINT if one of the operands is LONGINT;

the same applies to the ASR built-in function, but only for positive n; I'm not yet sure what actually happens for negative n, but it obviously works with my Oberon System version and it doesn't work anymore if I just replace >> n by << -n for negative n;

then there are two new BITSHL and BITSHR operations for logical left and right shift for positive n and again INTEGER and LONGINT;

finally I added the optional I and L suffix to integer literals to force either INTEGER (I) or LONGINT (L) type and thus to avoid SHORT() or LONG() operations;

the work in progress version of the spec (not yet commited) is attached:
The_Programming_Language_Oberon+.html.gz

from oberon.

rochus-keller avatar rochus-keller commented on July 29, 2024

Meanwhile I did a lot of practical experiments with the shift functions and finally could derive the true formula for ASR(x,n),

it is ASR(x,n) = x DIV 2^( n MOD w )^ with w the bit width of x.

As you can see it is different from the formula given in the Oberon spec (x DIV 2^n^), and ASR for negative n is not just a left shift (i.e. not the inverse operation of ASR, i.e. not LSL).

The formula for LSL is most likely LSL(x,n) = x * 2^( n MOD w )^ with w the bit width of x (I will do some experiments to confirm this).

Since the Oberon System (and likely other Wirth applications) depends on this feature I can't change it, otherwise these applications won't work anymore.

from oberon.

rochus-keller avatar rochus-keller commented on July 29, 2024

I added the BITASR(x,n) built-in function and deprecated ASR, ASH, LSL and ROR; please use the BITx functions and only for n >= 0 and < bitwidth; the functions work with both INTEGER and LONGINT.

I also refactored some other built-ins for LONG compatibility.

the work in progress version of the spec (not yet commited) is attached:

The_Programming_Language_Oberon+.html.gz

from oberon.

tenko avatar tenko commented on July 29, 2024

Happy new year.
Looks like a good choice with the BITXXX name convention.
Also removal of SHORT() or LONG() makes it much cleaner.
I will test this more when I get time to do so.

from oberon.

rochus-keller avatar rochus-keller commented on July 29, 2024

Thanks, same to you.

SHORT() and LONG() are still available, but since the literals can be typed it is less necessary to use them.

Meanwhile I added all necessary LONGINT and LONGREAL operations to the Oakwood library; commit will go up soon.

from oberon.

rochus-keller avatar rochus-keller commented on July 29, 2024

Can we close this?

from oberon.

tenko avatar tenko commented on July 29, 2024

We can close this.

from oberon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.