Post Reply 
Casio fx-50F/fx-50FH programming
09-26-2019, 07:34 AM (This post was last modified: 09-26-2019 07:36 AM by ijabbott.)
Post: #8
RE: Casio fx-50F/fx-50FH programming
(09-25-2019 04:22 PM)Csaba Tizedes Wrote:  SIGN(var) on CASIO: (var>0)-(var<0)
I really like how CASIOs are evaluates logical expressions.

Csaba

A similar trick can be used to determine the ordering of two numbers:

\( (a > b) - (a < b) \)

That yields -1, 0 or 1 depending on the ordering.

That's what I usually do to calculate the return value for comparison functions for use with the qsort() (quicksort) function in the C programming language standard library. In that case, the comparison function is allowed to return any integer because only the sign is used to determine the sort order of its two parameters. But using the above trick avoids arithmetic overflow and works for both signed and unsigned numbers. It is easy enough to modify the expression to reverse the ordering.

It doesn't necessarily generate the tightest binary code, but is pretty close to generating the tightest code, and it looks pretty.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Casio fx-50F/fx-50FH programming - ddd - 09-30-2019, 05:58 AM
RE: Casio fx-50F/fx-50FH programming - ijabbott - 09-26-2019 07:34 AM
RE: Casio fx-50F/fx-50FH programming - ddd - 09-12-2020, 07:31 AM
RE: Casio fx-50F/fx-50FH programming - ddd - 10-07-2020, 06:57 AM



User(s) browsing this thread: 1 Guest(s)