Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shortest useful program
#21
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!
Reply
#22
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?
*****
Reply
#23
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.
Reply
#24
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.
*****
Reply
#25
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)
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#26
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.
*****
Reply
#27
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
Reply
#28
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.
*****
Reply
#29
maybe they are working and i dont know what they're exsposed to do. :???:
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#30
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.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)