Posted By: earthquake

## Celcius => Fahrenheit conversion - 21/06/03 03:02 AM

Can someone give me steps as to how I would make an alias for this?

mIRC Homepage
# Celcius => Fahrenheit conversion

Posted By: earthquake
## Celcius => Fahrenheit conversion - 21/06/03 03:02 AM

Can someone give me steps as to how I would make an alias for this?

Posted By: KingTomato
## Re: Celcius => Fahrenheit conversion - 21/06/03 05:15 AM

Do u have the algorithm? (methods to convert)

Posted By: Jerk
## Re: Celcius => Fahrenheit conversion - 21/06/03 05:37 AM

Usage: $tempconv(Number,from,to)

$tempconv(32,F,C) returns 0

$tempconv(100,C,F) returns 212

$tempconv(100,C,K) returns 373.15

$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 }

Posted By: c0ldfusi0n
## Re: Celcius => Fahrenheit conversion - 21/06/03 10:13 AM

*applauds*

Posted By: Jesper
## Re: Celcius => Fahrenheit conversion - 21/06/03 10:49 AM

OMG what a messed script, it doesnt have to be that huge...

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

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

Posted By: Raccoon
## Re: Celcius => Fahrenheit conversion - 21/06/03 10:52 PM

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)

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. (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!)

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. (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!)

Posted By: Nobodi
## Re: Celcius => Fahrenheit conversion - 22/06/03 12:22 AM

But 5 divided by 9 doesn't equal 0.555556 though it's missing a few decimal places.

Posted By: Raccoon
## Re: Celcius => Fahrenheit conversion - 22/06/03 01:09 AM

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.

At least with 0.555556, there's one less DIV to process, making it that much faster.

Posted By: Nobodi
## Re: Celcius => Fahrenheit conversion - 22/06/03 04:33 AM

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)

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

Posted By: Raccoon
## Re: Celcius => Fahrenheit conversion - 22/06/03 04:45 AM

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

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

© 2022 mIRC Discussion Forums