News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Modulo function

Started by RGV250, May 25, 2021, 02:46 PM

Previous topic - Next topic

RGV250

Hi,
Does anyone know if there is a Modulo function in Positron, I have looked through the manual (8bit) but I may have missed it. I should be able to do it manually but just thought i would ask first.
It is to get the integer remainder from a division IE Modulo of 9 / 5 is 4.

Regards,
Bob

trastikata

#1
Quote from: RGV250 on May 25, 2021, 02:46 PMIt is to get the integer remainder from a division IE Modulo of 9 / 5 is 4.

Dim ModInt As Byte

ModInt = 9 // 5      'gives 4


RGV250

Thanks, I was looking at the list and always seem to miss things like that. I wonder if there could be an index sometime in the future.

Bob

top204

#3
With a PDF document there is no need for an index because a PDF viewer has a search mechanism. I also create relevant bookmarks, with sections, for the PDF manuals, so a click on the bookmark will take you to the relevant page. The default setting of the manual PDFs when I create them is to show the bookmarks on the left of the viewer screen, but some PDF viewers ignore the default settings within the PDF file. So enable the bookmarks in the viewer you are using, and you have an instant index.

I used the word Modulus in the manuals, instead of Modulo because when I was at school, the term for it was modulus. :-) I'll make a note and add the word modulo as a subtitle for the modulus operator in the next manuals update.

RGV250

Quotebecause a PDF viewer has a search mechanism
I thought that but I have never found it, maybe it is because I am using Firefox?

Bob

top204

I've used the Foxit reader for quite a few years now.

It is free and a good, small, viewer.

I used to use the Adobe reader, but it became bloated and was constantly monitoring the internet to pass bits and pieces of "private" information to the company, so I removed it and will never use it again.

trastikata

#6
Quote from: top204 on May 25, 2021, 04:41 PMI'll make a note and add the word modulo as a subtitle for the modulus operator in the next manuals update.

Les, I meant to ask you about the modulus function and the implementation in Positron/Proton but I forgot, so I'm taking the opportunity here ... In the documentation it is stated:
QuoteReturn the remainder left after dividing one unsigned or signed value by another

However some time ago I noticed it behaves differently than the other compilers - it returns the remainder of the absolute values' division, can you clarifying it? Here are some test results:
10 // 4 = 2
-10 // 4 = 2
10 // -4 = 2
-10 // -4 = 2
4 // 10 = 4
-4 // 10 = 4
4 // -10 = 4
-4 // -10 = 4

top204

#7
I'll check out the negative constant modulus functions of the compiler, but some of the above are correct, so I'll go through the functions one by one and see where they are not detecting a negative constant correctly.

With constants only being used in an expression, the compiler uses the C++ functions, just like an interpreter, then loadd the variable with its result, so I'll check out the modulus functions using the '%' operator.