Since some hours I realized that my app for finding socalled Emirpnumbers (very great primes and the reverses of them) always missed some results. And now I now why. I use the wonderful fp plugin from Robert Delaney and always use BigIntegers here. But I must use integer divide and not the usual divide for calculating the reverse numbers.

Here is the problem:

While n <> 0

d = n Mod 10

rev = rev * 10 + d

n = n \ 10 <— problem!!! (n = n / 10 makes problems in the resulting numbers)

Wend

Undefined operator. Type BigInteger does not define “Operator_IntegerDivide” with type Int64

n = n \ 10

Can anybody here help me? This would be great. Without the fp plugin I can’t use very big numbers in Xojo (but here all is ok with integer divide ).

Many thanks in advance… Peter

Many thanks brian. I’v downloaded the version 12.0 and try it now. Again, thank you!

update: have tested version 12 now, but the problem is still the same!

But if n is some integer kind “n = n / 10” should result in the same result of “n = n \ 10” as fractions are discarded. Where am I missing something?

This is really a problem. Obviously “n = n \ 10" wasn’t accepted when n is of type BigInteger. Curiously in the error message it is called Int64. Don’t know why.

Xojo Integer is Int64 when your on 64 bit platform and Int32 when your on 32 bit platform.

But the plugin has no Divide operators fir BigInteger. But as Rick said above then since your not dealing with floating point then its unclear what result you would be expecting different from \ operator over / operator.

1 Like

Hi Björn, I expect an integer (BigInteger) result. But I alwys get a error. And I can’t use BigFloat because i use the very fast fpisPrime-function from the fp plugin.

The error you get above with the backwards operator is since this class does not have that operator.

So the question is what are you getting wrong by using the normal “/” operator ? What value are you feeding to it, what result do you get and what did you expect ?

I thought this already. But thank you Björn. I have the program without the plugin too and there I receive much more primes than with the fp plugin and the normal “/” operator. But without the plugin I can’t test very big numbers. This is the main problem.

I’ve encountered problems when evaluating expressions containing numeric literals. What happens if you do the following?

```
dim k10 As new BigInteger("10")
While n <> 0
d = n Mod k10
rev = rev * k10 + d
n = n / k10
Wend
```

I still do not got any info on what exactly is not working for you, what the value is that you divide and what result you get and what result you expected.

There is no way to fix anything if you just say its “broken”

1 Like

Robert, thank you. I tested it now with your advice using k10 instead of 10. Same problem as before.

Björn thank you again. I try to find a way to describe the problem better. Sorry. I hope I find a better explanation soon…

Let me help you. Write a small and complete sample of the problem. Show a problematic value in debug, maybe using System.Debuglog stringValue, and show what you expected like System.Debuglog “it should be 123”

So people could SEE the problem.

3 Likes

I’ve played around with this and can confirm that there is a problem, but it’s not with the division operation, it’s with the mod operator. The OP’s code is intended to reverse the digits of a bigInt. I’ve duplicated it here, and added some steps to output the digits one at a time in the while/wend loop.

```
dim n As new BigInteger("123473943748948377847329482759365020183746936265")
'Output the original BigInt
efOut.Text = Str(n)+EndOfLine
dim k10 As new BigInteger("10")
dim d As new BigInteger
dim rev As new BigInteger("0")
while n>0
d = n mod k10
'Output the reversed bigInt one digit at a time
efOut.AppendText(str(d)+" ")
rev = rev*k10+d
n=n/k10
wend
efOut.AppendText EndOfLine
'Output the completely assembled reversed bigInt
efOut.AppendText Str(rev)+EndOfLine
```

This is the output to the textfield:

```
123473943748948377847329482759365020183746936265
5 -4 2 -4 3 -1 -4 4 -3 3 -2 1 0 2 0 5 -4 3 -1 5 -3 2 -2 4 -1 2 3 -3 4 -2 -3 -3 3 -2 4 -1 -2 4 -3 3 4 -1 3 -3 4 3 2 1
461628637281020462947183922737672838837339274321
```

Notice that when the mod 10 value should be between 5 and 9, the result has 10 subtracted from it, making it negative.

Workaround:

```
while n>0
d = n mod k10
if d<0 then d=d+k10 '<-- Workaround to fix mod operator error
rev = rev*k10+d
n=n/k10
wend
```

Robert, thank you very very much. You helped me very much. Now all works like it should. Never thought at the mod operator before. After inserting k10,d and rev as new BigInteger and changing n <> 0 to n > 0 and adapting the while loop, everything works great. I will change this now in all my other programs where I use the fp plugin and mod too.

Again many thanks for your great help, I learned much from your help too,

Peter

This is the correct answer of my program now and only because of your help.

1 Like

I put in fix for next version.

I don’t know when next version will come.

If you don’t mind then I will put attribution in the docs for your finding.

1 Like

Björn this is great, thank you. Now all works as it should. I show two images of the results of my program. By the way, I am very happy now, really…

1 Like

Have you found the real bug in mod() or are thinking in adding y to r in r = x mod y when finding a negative r? (as in the workaround). If the second option, you will introduce a new bug.

I assume Björn is capable of finding the actual bug and and conscientious enough to fix it properly.