Posts: 3,343
Threads: 83
Joined: Mar 2003
Reasonable idea. How about we start with a few one line functions:
Code:
DEF FNround# (m#) = SGN(m#) * INT(100 * ABS(m#) + .5) / 100
DEF FNmin (a, b) = a * ABS(a <= b) + b * ABS(a > b)
DEF FNmax (a, b) = a * ABS(a >= b) + b * ABS(a < b)
DEF FNroll3D6% = INT(6 * RND) + INT(6 * RND) + INT(6 * RND) + 3
DEF FNflip$ = MID$("HEADTAIL", 4 * INT(2 * RND) + 1, 4)
Now, lets see some real entries!
Posts: 1,956
Threads: 65
Joined: Jun 2003
ORACLE:
I was looking at your functions. The one for rounding is really clever, neat, all on one line, with no if's, and's or but's.
Then you have two functions called FNmin. Shouldn't one of these be FNmax?
What exactly do they do? I'll guess that on a "min" it will return the value of the lesser parameter, no? If that's so, then why go through the trouble of using a function, why not just do an "if a < b..."? Am I missing something?
*****
Posts: 3,343
Threads: 83
Joined: Mar 2003
Changed the wrong min to max. Copy&paste...
The min and max function return the value of the smallest and largest, not true or false based on whether one is larger.
Posts: 1,956
Threads: 65
Joined: Jun 2003
Oracle,
BTW, I tested your rounding function. I think it assumes an input value with two implied decimal points. To make it more general and allow input values with explicit decimals, I removed the multiply and the divide y 100. It then works fine for me.
This clever little function of yours avoids the fact that the INT in QB will round a negative number up instead of down. Example: if I do
INT(123.9) ... I get 123. But if I do
INT(-123.9)... I get 124...... More Basic weirdness.
*****
Posts: 2,765
Threads: 138
Joined: Nov 2002
I couldn't get my nand and nor to work.
but here anyway
Code:
DEF FNnand (a,b) = NOT (a AND b)
DEF FNnor (a,b) = NOT (a OR b)
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 1,956
Threads: 65
Joined: Jun 2003
Whitey,
I'm not up on logic circuit design, but consider the following:
Code:
NOT(a and b) = NOT(a) or NOT(b)
NOT(a or b) = NOT(a) and NOT(b)
I'm not sure if you can derive NAND and NOR from this, but it doesn't seem to be as straightforward as you had it. I could be wrong.
*****
Posts: 594
Threads: 11
Joined: Oct 2002
Quote:Code:
DEF FNround# (m#) = SGN(m#) * INT(100 * ABS(m#) + .5) / 100
Here's a better round function... ( I only changed one thing )
Code:
DEF FNround# (m#, dec%) = SGN(m#) * INT(10^dec% * ABS(m#) + .5) / 10 ^ dec%
B 4 EVER
Posts: 1,956
Threads: 65
Joined: Jun 2003
WHITEY,
Regarding your functions for NAND and NOR, I checked further and they look fine just the way you have them. Don't know why they won't work for you.
*****
Posts: 2,765
Threads: 138
Joined: Nov 2002
maybe they are working and i dont know what they're exsposed to do. :???:
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 1,956
Threads: 65
Joined: Jun 2003
Quote:... Here's a better round function... ( I only changed one thing )Code:
DEF FNround# (m#, dec%) = SGN(m#) * INT(10^dec% * ABS(m#) + .5) / 10 ^ dec%
AK00MA:
Excellent, although you didn't declare what feature you added. I assume from the code that dec% declares the number of IMPLIED decimals contained in the number in m#. If this is the case, then you enhanced Oracle's general purpose function with this added feature.
*****