Page 1 of 2
Posted: Tue Jan 14, 2003 11:11 am
by BackupUser
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]
Posted: Tue Jan 14, 2003 11:21 am
by BackupUser
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:
Code: Select all
Procedure MOD(a,b)
ProcedureReturn a-a/b*b
EndProcedure
Posted: Mon Jan 20, 2003 6:04 pm
by BackupUser
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/
--
Posted: Mon Jan 20, 2003 7:34 pm
by BackupUser
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
Posted: Tue Jan 21, 2003 6:51 pm
by BackupUser
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/
--
Posted: Tue Jan 21, 2003 7:46 pm
by BackupUser
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]
Posted: Tue Jan 28, 2003 10:04 pm
by BackupUser
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...??
Posted: Tue Jan 28, 2003 10:54 pm
by BackupUser
Restored from previous forum. Originally posted by tinman.
Originally posted by mindplay
overhead, and multiplication and division are "expensive" operators, whereas the modulus function is ordinarily a very "cheap" function...
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.
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)
Posted: Wed Jan 29, 2003 9:00 am
by BackupUser
Restored from previous forum. Originally posted by fred.
If you find a mod function in the ASM opcode, I would be very glad...
Fred - AlphaSND
Posted: Wed Jan 29, 2003 1:22 pm
by BackupUser
Restored from previous forum. Originally posted by tinman.
Originally posted by fred
If you find a mod function in the ASM opcode, I would be very glad...
The DIV instruction seems to produce the modulus as an additional feature of the calculation, in the same way the 68k divide instructions do.
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
Posted: Wed Jan 29, 2003 2:56 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
Very interresting, thanks for the hint, I will take a deeper look.
Fred - AlphaSND
Posted: Wed Jan 29, 2003 4:57 pm
by BackupUser
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?
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)
@Manolo: the file you linked to is about 16 bit maths, but it's also interesting. ¡Nunca máis!
Bye,
El_Choni
Posted: Wed Jan 29, 2003 5:07 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
You rock El Choni, thanks for your suggestions !
Fred - AlphaSND
Posted: Tue Jun 17, 2003 2:31 am
by Karbon
Hey hey.. what's happening with the mod operator?
Purely out of curiosity - is this a hard thing to implement?
Posted: Tue Jul 15, 2003 6:43 pm
by mp303
will this operator ever be implemented? looking back through the posts in the forum, it was first requested in november 2001 ... that's 18 months ago
