----boundary-LibPST-iamunique-1105271097_-_-
Content-type: text/plain
> > What is the best thing to do in CP?
Three possibilities come to mind:
1 - Simplest, but not fastest.
- Use LONGINTs.
2 - Use a different random numnber generator.
Examples of good ones have been published
by myself & Fyodor.
3 - If you really want your precise function to
execute at maximum speed use a 1 instruction
in-line [Code] function - for an example
see LibIntegers.MultMod.
The compromise that CP has adopted between language
simplicity and utmost efficiency under all
circumstances is not perfect for all circumstances,
but no compromise can be.
I like the COP compromise for two reasons:
1 - I like it!
2 - Better to have 1 c and 1 CP than 2 c's.
Robert
ps I don't have the knowledge to help write the
1-line Code procedure!
>> > Andrew,
>> >
>> > 1. Generally, the Component Pascal MOD operator is the
>> equivalent of the %
>> > (modulus) operator in C. Note that MOD is defined in
>> terms of DIV and CP
>> DIV
>> > always rounds toward negative infinity. Most C-language
>> implementations
>> > normally round towards zero.
>> >
>> > 2. What is the specific problem you have with the return
>> statement?
>> >
>>
>> Hi Chris,
>>
>> the problem is that the divide is by MAX(unsigned integer)
>>
>> Andrew
>>
>> > Regards,
>> >
>> > Chris Burrows
>> > CFB Software
>> > info{([at]})nowhere.xy>> > http://www.cfbsoftware.com
>> >
>> >
>> > >
>> > > -----Original Message-----
>> > > From: blackbox{([at]})nowhere.xy>> Behalf Of Andrew
>> > > Thomas
>> > > Sent: Friday, 25 March 2005 12:52 AM
>> > > To: BlackBox Mailing List
>> > > Subject: [BlackBox] - Bit operations in Component Pascal
>> > >
>> > >
>> > > Moi,
>> > >
>> > > Yes SET is great and it is easy to go from SET to
>> INTEGER. Things are
>> much
>> > > uglier in C. However C has an 4 byte unsigned integer
>> and you can
>> > > manipulate
>> > > this as bits using <<, >>, ^ etc. This is very useful
>> for writing random
>> > > number generators where you can write
>> >
>> > <snip>
>> > > x[kk] = x[kk+M] ^ (x[kk] >> 1) ^ mag01[x[kk] % 2];
>> >
>> > <snip>
>> > > return( (double) y / (unsigned long) 0xffffffff);
>> > >
>> > > The problem I have with the C code is x[kk] % 2 and the return
>> statement.
>> > > What is the best thing to do in CP?
>> > >
>> > > Regards
>> > > Andrew
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
----boundary-LibPST-iamunique-1105271097_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIFxwYXINClxwYXINCj4gPiBXaGF0IGlzIHRoZSBi
ZXN0IHRoaW5nIHRvIGRvIGluIENQP1xwYXINClxwYXINClRocmVlIHBvc3NpYmlsaXRpZXMgY29t
ZSB0byBtaW5kOlxwYXINClxwYXINCjEgLSBTaW1wbGVzdCwgYnV0IG5vdCBmYXN0ZXN0LlxwYXIN
ClxwYXINCiAgLSAgVXNlIExPTkdJTlRzLlxwYXINClxwYXINCjIgLSBVc2UgYSBkaWZmZXJlbnQg
cmFuZG9tIG51bW5iZXIgZ2VuZXJhdG9yLlxwYXINCiAgICBFeGFtcGxlcyBvZiBnb29kIG9uZXMg
aGF2ZSBiZWVuIHB1Ymxpc2hlZFxwYXINCiAgICBieSBteXNlbGYgJiBGeW9kb3IuXHBhcg0KXHBh
cg0KMyAtIElmIHlvdSByZWF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rYm94QG9iZXJvbi5jaFxwYXINCn19AGplY3Q
----boundary-LibPST-iamunique-1105271097_-_---
Received on Tue Mar 29 2005 - 10:37:25 UTC