Are we missing modulo (%) operator in Jack?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Are we missing modulo (%) operator in Jack?

ganesshk
This post was updated on .
Is there any specific reason why there is no modulo(%) operator in the Jack language?

Maybe we can add a method mod(x, y) to Math module
Reply | Threaded
Open this post in threaded view
|

Re: Are we missing modulo (%) operator in Jack?

cadet1620
Administrator
ganesshk wrote
Is there any specific reason why there is no modulo(%) operator in the Jack language?

Maybe we can add a method mod(x, y) to Math module
Jack was designed to be a minimal, but useable, object oriented programming language. It would be extra programming work for the students if they had to support '%' in the compiler they write in projects 10-11, and to write the Math.mod function in the OS they write in project 12.

Although it is less efficient than a direct implementation, a%b can be done as a-(a/b*b).

As a Chapter 13 project, you could add Math.mod(x, y) to your OS and support the '%' operator in your Jack compiler.

--Mark