RE: Predeclared function CAP

From: CFB Software <"CFB>
Date: Thu, 16 Sep 2004 15:44:51 +0930

----boundary-LibPST-iamunique-337536635_-_-
Content-type: text/plain

> -----Original Message-----
> From: Gérard Meunier [mailto:gemeu{([at]})nowhere.xy
>
> > recently I ran into some mischief using the predeclared Compiler
> > Function CAP because the result was somewhat unexpected.
> The results
> > and the problem can be found in the following coded text, perhaps
> > somebody knows an answer:
>
> Apparently, this function substracts 32 (20H) from the code
> of many characters. It's correct for lower case letters, but
> a little surprising for digits or punctuations. I don't know
> why this behaviour has been chosen. I never use CAP myself
> but Strings.Upper, which works properly, but may be a little slower.
>

CAP is useful where execution speed is absolutely crucial. Timing tests
indicate that it is about 4 times faster than Strings.Upper.

It is no accident that capital letters in the Latin-1 character set only
differ from the corresponding lowercase letter by one bit. I don't know
how exactly how BlackBox does it but typically a compiler just needs to
generate a single bitwise AND operation to clear one bit to implement
CAP. Unlike a call to Strings.Upper, no function call / return or
pushing / popping parameters to / from the stack is involved.

I find it useful (and safe) in situations like:

  IF (CAP(ch) >= 'A') OR (CAP(ch) <= 'Z') THEN

instead of

  IF ((ch >= 'a') & (ch <= 'z')) OR ((ch >= 'A') & (ch <= 'Z')

However, if speed is not a priority, and you want to take the safe
route, your recommendation to use Strings.Upper is a good one.


Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp




--------------------------------------------

To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xy

To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.

Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy

Current posting policy:

a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.

b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.


----boundary-LibPST-iamunique-337536635_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-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2013 - 06:28:36 UTC