From WikiChip
Difference between revisions of "mirc/identifiers/$ord"
< mirc‎ | identifiers

(Created page with "{{mirc title|$ord Identifier}}'''$ord''' appends "st", "nd", "rd", or "th" as appropriate, to the number N. == Synopsis == <pre>$ord(N)</pre> == Paramters == * '''N''' -...")
 
 
Line 1: Line 1:
 
{{mirc title|$ord Identifier}}'''$ord''' appends "st", "nd", "rd", or "th" as appropriate, to the number N.
 
{{mirc title|$ord Identifier}}'''$ord''' appends "st", "nd", "rd", or "th" as appropriate, to the number N.
 
 
 
 
 
== Synopsis ==
 
== Synopsis ==
 
<pre>$ord(N)</pre>
 
<pre>$ord(N)</pre>
 
+
== Parameters ==
== Paramters ==
 
 
 
 
* '''N''' - The number
 
* '''N''' - The number
 
 
== Properties ==
 
== Properties ==
 
None
 
None
 
 
== Example ==
 
== Example ==
 
<source lang="mIRC">//echo -a $ord(3)</source>
 
<source lang="mIRC">//echo -a $ord(3)</source>
 +
Rules:
 +
# If number ends with 11 12 or 13, suffix is th
 +
# If number ends with 1        the suffix is st
 +
# If number ends with 2        the suffix is nd
 +
# If number ends with 3        the suffix is rd
 +
# All other numbers end with th, including zero.
 +
 +
This code shows that following these 5 rules produces the same output as letting mIRC calculate the Ordinal. It repeatedly hashes a string consisting of the previous hash combined with the $ord of the next number, and both methods produce the identical hash:
 +
 +
<source lang="mIRC">
 +
//var %a , %a2 , %i 0 | while (%i isnum 0-999) { if ($istok(11 12 13,$right(%i,2),32)) var %ord th | elseif ($findtok(1 2 3,$right(%i,1),1,32)) var %ord $gettok(st nd rd,$v1,32) | else var %ord th | var %a $sha1(%a %i $+ %ord) , %a2 $sha1(%a2 $ord(%i)) | inc %i } | echo -a %a , %a2
 +
</source>
  
 +
For fractions, the $ord uses the last 1 or 2 digits of the fraction.
 +
<source lang="mIRC">
 +
//echo -a $ord(2.1) and $ord($pi)
 +
</source>
 
== Compatibility ==
 
== Compatibility ==
 
{{mIRC compatibility|5.61}}
 
{{mIRC compatibility|5.61}}
 
 
== See Also ==
 
== See Also ==
 
[[Category:mIRC identifiers]]
 

Latest revision as of 04:26, 18 January 2019

$ord appends "st", "nd", "rd", or "th" as appropriate, to the number N.

Synopsis[edit]

$ord(N)

Parameters[edit]

  • N - The number

Properties[edit]

None

Example[edit]

//echo -a $ord(3)

Rules:

  1. If number ends with 11 12 or 13, suffix is th
  2. If number ends with 1 the suffix is st
  3. If number ends with 2 the suffix is nd
  4. If number ends with 3 the suffix is rd
  5. All other numbers end with th, including zero.

This code shows that following these 5 rules produces the same output as letting mIRC calculate the Ordinal. It repeatedly hashes a string consisting of the previous hash combined with the $ord of the next number, and both methods produce the identical hash:

//var %a , %a2 , %i 0 | while (%i isnum 0-999) { if ($istok(11 12 13,$right(%i,2),32)) var %ord th | elseif ($findtok(1 2 3,$right(%i,1),1,32)) var %ord $gettok(st nd rd,$v1,32) | else var %ord th | var %a $sha1(%a %i $+ %ord) , %a2 $sha1(%a2 $ord(%i)) | inc %i } | echo -a %a , %a2

For fractions, the $ord uses the last 1 or 2 digits of the fraction.

//echo -a $ord(2.1) and $ord($pi)

Compatibility[edit]

Added: mIRC v5.61
Added on: 23 Sep 1999
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.

See Also[edit]