@verb #8084:"@convert-speed" any at/to any rdo #8084 @program #8084:"@convert-speed" any at/to any "Converts one speed to another form. '@convert *number* *unit* to *unit*'. The number may be floating point. The unit consists of four parts, the multiplier (ie, 'k' for kilo, 'm' for milli, 'M' for mega, 'T' for terra', 'G' for giga.) [optional], the what (b for bits, B for bytes), the letter 'p' or a / to represent 'per', and a unit of time (s = seconds, m = minutes, Y = years, d = days)" from = dobjstr to = iobjstr mcf = {{"n", 1e-12}, {"p", 1e-09}, {"u", 1e-06}, {"m", 0.001}, {"c", 0.01}, {"d", 0.1}, {"D", 10.0}, {"h", 100.0}, {"k", 1000.0}, {"M", 1000000.0}, {"G", 1000000000.0}, {"T", 1000000000000.0}} tcf = {{"s", 1.0}, {"m", 60.0}, {"h", 60.0 * 60.0}, {"d", 60.0 * 60.0 * 24.0}, {"y", 60.0 * 60.0 * 24.0 * 365.25}} "Go from 'from' to bps, then from bps to 'to'." number = from[1..index(from, " ") - 1] fromunit = from[index(from, " ") + 1..$] if (length(fromunit) != 3 && length(fromunit) != 4) return player:tell("Your from unit must be 3 or 4 chars long.") endif frommulti = 1.0 if (length(fromunit) == 4) cf = fromunit[1] for x in (mcf) if (equal(x[1], cf)) conv = x[2] break endif endfor if (!`conv ! E_VARNF') return player:tell("Invalid metric conversion factor in your from unit.") endif frommulti = conv endif bit = length(fromunit) == 4 ? equal(fromunit[2], "b") | equal(fromunit[1], "b") for x in (tcf) if (equal(x[1], fromunit[$])) fromtimeconv = x[2] break endif endfor if (!`fromtimeconv ! E_VARNF') return player:tell("Invalid time conversion factor in your from unit.") endif "Convert to bps." bps = tofloat(number) * frommulti * (bit ? 1.0 | 8.0) / fromtimeconv if (length(to) != 3 && length(to) != 4) return player:tell("Your to unit must be 3 or 4 chars long.") endif tomulti = 1.0 if (length(to) == 4) cf = to[1] for x in (mcf) if (equal(x[1], cf)) _conv = x[2] break endif endfor if (!`_conv ! E_VARNF') return player:tell("Invalid metric conversion factor in your to unit.") endif tomulti = _conv endif bit = length(to) == 4 ? equal(to[2], "b") | equal(to[1], "b") for x in (tcf) if (equal(x[1], to[$])) totimeconv = x[2] break endif endfor if (!`totimeconv ! E_VARNF') return player:tell("Invalid time conversion factor in your to unit.") endif final = bps / (bit ? 1.0 | 8.0) * totimeconv / tomulti player:tell(tofloat(number), " ", fromunit, " is ", final, " ", to, ".") "Last modified by Lao-Tzu (#8084) on Mon Apr 24 12:46:34 2000 EDT." .