mIRC Home    About    Download    Register    News    Help

Print Thread
#42332 17/08/03 08:46 AM
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
I would like to suggest that $calc support an interger-divide operator, such as \, to produce a whole number when dividing.

Examples:
$calc(9 \ 2) == $int($calc(9 / 2)) == 4
$calc(9 \ 2 * 4) == $calc($int($calc(9 / 2)) * 4) == 16
$calc(23 \ 2 \ 2 \ 2) == $int($calc($int($calc($int($calc(23 / 2)) / 2)) / 2)) == 2

I believe I've seen this method implimented in various languages as either \ or //.

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 56
W
Babel fish
Offline
Babel fish
W
Joined: Dec 2002
Posts: 56
$calc(n1-(n1 % n2))


Acquire. Analyze. Adapt.
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Lets say we have: $calc(11 \ 5)

$calc(11-(11 % 5)) == 10 <- Bad Idea. mad
$int($calc(11 / 5)) == 2 <- Bling Bling! laugh

I think we've established that it's already POSSIBLE to do int-division without changing anything. That's not the issue here.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Not a bad idea at all. Btw, I'd also like a second parameter to $calc, which would be able to do int-ing and rounding. It would be a number; -1 (or smaller/non-numeric) would do int-ing, 0 and greater would do rounding.

$calc(5 / 3,0) = $round($calc(5 / 3),0) = 2
$calc(5 / 3,1) = $round($calc(5 / 3),1) = 1.7
$calc(5 / 3,-1) = $int($calc(5 / 3)) = 1


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Great idea!!! grin


Well. At least I won lunch.
Good philosophy, see good in bad, I like!

Link Copied to Clipboard