[Feature Request] - Modulus/Remainder
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Num3.
Hi,
It seems that PB does not have a Modulus/Remainder aka MOD function.
The function does the following:
Returns the remainder of the division
ie. 15 MOD 10
is 15/10 whose remainder is 5
--
Kind Regards
Rui Carvalho
[DURON 1K - 256Mb - 40Gb - GFORCE MX2 64Mb - W2K PRO]
Hi,
It seems that PB does not have a Modulus/Remainder aka MOD function.
The function does the following:
Returns the remainder of the division
ie. 15 MOD 10
is 15/10 whose remainder is 5
--
Kind Regards
Rui Carvalho
[DURON 1K - 256Mb - 40Gb - GFORCE MX2 64Mb - W2K PRO]
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> It seems that PB does not have a Modulus/Remainder aka MOD function.
Until it does, just use this procedure:
> It seems that PB does not have a Modulus/Remainder aka MOD function.
Until it does, just use this procedure:
Code: Select all
Procedure MOD(a,b)
ProcedureReturn a-a/b*b
EndProcedure
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Hi-Toro.
I was just looking for this!
--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
I was just looking for this!
--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Berikco.
Guess its posted now 5 times in the forum, and its in the Purebasic Editor source
Regards,
Berikco
http://www.benny.zeb.be/purebasic.htm
Guess its posted now 5 times in the forum, and its in the Purebasic Editor source

Regards,
Berikco
http://www.benny.zeb.be/purebasic.htm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Hi-Toro.
Not really the best place for it...!
--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
Not really the best place for it...!
--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Berikco.
I agree, whe should take it out the PB Editor source
Some searching gave me this result....
Shows again how difficult it is to find what you need in forum
Maybe adding keywords (as i read in other post here today) is not a bad idea?
viewtopic.php?t=4548">http://forums.pur ... php?t=2287
viewtopic.php?t=4479
Regards,
Berikco
<a href="http://www.benny.zeb.be/purebasic.htm[/url]
I agree, whe should take it out the PB Editor source
Some searching gave me this result....
Shows again how difficult it is to find what you need in forum
Maybe adding keywords (as i read in other post here today) is not a bad idea?
viewtopic.php?t=4548">http://forums.pur ... php?t=2287
viewtopic.php?t=4479
Regards,
Berikco
<a href="http://www.benny.zeb.be/purebasic.htm[/url]
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by mindplay.
This of course is a way around the missing feature, but it's not really a solution - I badly need a modulus function myself, but one that will perform like an ordinary modulus function, in terms of CPU usage ... the above solution probably requires at least 100 times the CPU power of an ordinary modulus operator, due to procedure call overhead, and multiplication and division are "expensive" operators, whereas the modulus function is ordinarily a very "cheap" function...
Any word on wether this will be added? should be dead simple...??
This of course is a way around the missing feature, but it's not really a solution - I badly need a modulus function myself, but one that will perform like an ordinary modulus function, in terms of CPU usage ... the above solution probably requires at least 100 times the CPU power of an ordinary modulus operator, due to procedure call overhead, and multiplication and division are "expensive" operators, whereas the modulus function is ordinarily a very "cheap" function...
Any word on wether this will be added? should be dead simple...??
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tinman.
Still, I agree that it will be a lot faster than the procedure workaround.
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
How do you get the modulus without at least one multiplication or division? Even CPUs which have a "built in" modulus calculation usually work it out as the result of a divide.Originally posted by mindplay
overhead, and multiplication and division are "expensive" operators, whereas the modulus function is ordinarily a very "cheap" function...
Still, I agree that it will be a lot faster than the procedure workaround.
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tinman.
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
The DIV instruction seems to produce the modulus as an additional feature of the calculation, in the same way the 68k divide instructions do.Originally posted by fred
If you find a mod function in the ASM opcode, I would be very glad...
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
This is what I've found out so far about modulus. Maybe, if further optimized, it could be integrated into PB?
@Manolo: the file you linked to is about 16 bit maths, but it's also interesting. ¡Nunca máis! 
Bye,
El_Choni
This is what I've found out so far about modulus. Maybe, if further optimized, it could be integrated into PB?
Code: Select all
;c = Mod(a, b):
;-------------
;1. For integers:
a = 12
b = 5
c.l
mov eax, a
push ecx
mov ecx, b
xor edx, edx
div ecx
mov c, edx
pop ecx
MessageRequester("", Str(c), 0)
;2. For b=2^n:
a = 15
b = 4
mov edx, b
dec edx
mov eax, a
and eax, edx
mov c, eax
MessageRequester("", Str(c), 0)
;3. For fp numbers:
fa.f = 11.5
fb.f = 4
fc.f
!fld dword [v_fb]
!fld dword [v_fa]
!fprem
!fstp dword [v_fc]
!fdecstp
MessageRequester("", StrF(fc, 1), 0)

Bye,
El_Choni
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Hey hey.. what's happening with the mod operator?
Purely out of curiosity - is this a hard thing to implement?
Purely out of curiosity - is this a hard thing to implement?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net