mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 3
E
Self-satisified door
OP Offline
Self-satisified door
E
Joined: Feb 2003
Posts: 3
Can someone give me steps as to how I would make an alias for this?

Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Do u have the algorithm? (methods to convert)


-KingTomato
Joined: Dec 2002
Posts: 169
J
Vogon poet
Offline
Vogon poet
J
Joined: Dec 2002
Posts: 169
Usage: $tempconv(Number,from,to)
$tempconv(32,F,C) returns 0
$tempconv(100,C,F) returns 212
$tempconv(100,C,K) returns 373.15

Code:
alias tempconv {
  if ( ($$1 isnum) && ($regex($$2,^[cfkCFK]$)) && ($regex($$3,^[cfkCFK]$)) ) {
    if ($$2 == F) {
      if ($$3 == F) { return $$1 }
      if ($$3 == C) { return $calc(($$1 - 32) * 5 / 9) }
      if ($$3 == K) { return $calc(($$1 - 32) * 5 / 9 + 273.15) }
    }
    if ($$2 == C) {
      if ($$3 == F) { return $calc(($$1 * 9 / 5) + 32) }
      if ($$3 == C) { return $$1 }
      if ($$3 == K) { return $calc($$1 + 273.15) }
    }
    if ($$2 == K) {
      if ($$3 == F) { return $calc(($$1 - 273.15) * 9 / 5 + 32) }
      if ($$3 == C) { return $calc($$1 - 273.15) }
      if ($$3 == K) { return $$1 }
    }
  }
  echo $color(info) -esti * Error: $!tempconv called with invalid parameters }
  return
}

Last edited by Jerk; 21/06/03 05:46 AM.
Joined: Mar 2003
Posts: 272
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Mar 2003
Posts: 272
*applauds*


- cF
Dedicated helper for rent.
Joined: Jan 2003
Posts: 96
J
Babel fish
Offline
Babel fish
J
Joined: Jan 2003
Posts: 96
OMG what a messed script, it doesnt have to be that huge... wink

Code:
Alias temp {
  var %t = $left($1,-1)
  var %s = $right($1,1)
  if (F == %s) { return $1 ( $+ $round($calc((%t - 32) / 1.8),2) $+ C $+ ) }
  if (C == %s) { return $1 ( $+ $round($calc((%t * 1.8) + 32),2) $+ F $+ ) }
  if (K == %s) { return $1 ( $+ $round($calc(%t - 273.15),2) $+ C $+ ) ( $+ $round($calc(((%t - 273.15) * 1.8) + 32),2) $+ F $+ ) }
}


Usage //say $temp(100F)
Returns 100F (37.78C)
Usage //say $temp(100C)
Returns 100C (212F)
Usage //say $temp(100K)
Returns 100K (-173.15C) (-279.67F)
or use //echo :tongue:


_____
Yes I was away wink

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Well, I wouldn't say it's messed up, maybe just a tad redundant though. However, your script is lacking options that his has.

Adlibbed & untested.
$therm(N,KFC,KFC)
Code:
ALIAS Therm {
  var %n = $$1, %in = $$2, %out = $$3
  if ( %in == F ) var %in = C, %n = $calc((%n - 32) * 0.555556
  if ( %in == C ) var %n = $calc(%n - 273.15)
  if ( %out == K) return %n
  var %n = $calc(%n + 273.15)
  if ( %out == C ) return %n
  var %n = $calc(%n * 1.8 + 32)
  return %n
}


Basically, I convert from F to C and C to K, then convert from K to C and C to F... starting/stopping on whichever unit specified. This method may convert from temp to temp to temp (C to K to F), meaning more steps than Jerk's method... yet, I feel the reduced code speeds up the process enough to make up for it. You can also use C or F as the base unit, instead of K.

You'll also note that 9 / 5 was replaced with 1.8, and 5 / 9 was replaced with 0.555556 for speed.

Someone test this and tell me if it actually works. grin (Yes, I'm such an arrogant sob today)

- Raccoon

PS. People who paste [[/b]code] snippets that cause a scrollbar on 1024x786 resolution, need to be shot. $&
[b]Break your code into multiple lines!!!
$&
(we rather scroll vertically, NOT horizontally!)


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 191
N
Vogon poet
Offline
Vogon poet
N
Joined: Dec 2002
Posts: 191
But 5 divided by 9 doesn't equal 0.555556 though it's missing a few decimal places.

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
That is the extent that mIRC is able to calculate 5/9 anyway, so it is as accurate as it will ever be.
At least with 0.555556, there's one less DIV to process, making it that much faster.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 191
N
Vogon poet
Offline
Vogon poet
N
Joined: Dec 2002
Posts: 191
mirc will still use the correct numbers internally in the calulation, just rounds to 6 decimal places in what it returns.

//echo -ag $calc((5/9)*9) , $calc(0.555556*9)

Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
touché. Keen observation.

However I just found $calc(0.5555555*9) [7 decimal places] seems to work. I knew $calc will only return up to 6 decimal places, but I guess if you feed it 7 decimal places or more, it still calculates them correctly. So when it gets to rounding down to 6 places, it works out.

Thanks for pointing that out though.

- Raccoon


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

Link Copied to Clipboard