Rowan home > Reference > Promote/demote

Promote/Demote: Monadic and

Module: Main
Syntax: ⍏/⍖ any : any
Errors: none
Default Rank: -1
Keystrokes: Ctrl+Shift+Y, Ctrl+Shift+U

These functions promote and demote (widen and narrow) numeric types, while leaving other sorts of data alone. They are most useful for making sure parameters to be passed to external function calls are of the correct type, as within Rowan it does not usually matter what type a number is represented as. You might want to use to avoid an overflow with large values represented as integers, for example.

The sequence of types is: bool, int, float, double, LargeInteger.
moves the data up one type at a time (and always preserves precision), moves it down one at a time, losing precision as it does so. (Note that Rowan does not support float type data, so you cannot use primitives on numbers you have converted to float.) When converting from bool to int, the result is either 0 or 1; when converting from int to bool, any non-zero value is converted to true.

For example:

   (⍏⍏1):GetType
System.Double
   ⍖⍖3.2     // double to int
3
   ⍖⍖-3.2    // double to int
-3
  ⍖⍖⍖-3.2  // double to bool
True
   ⍏1.17    // double to extended
1.17`