cast

cast (value schema -- convertedValue)

Inputs

Outputs

cast converts a Cond or numeric value to the selected numeric schema.

The schema input is used only as a numeric schema selector. Its value is not read.

Behavior

Example

{} 0 {} [
  "-- schema selector value ignored --" printCompilerMessage
  7 0n8 cast printStack _:;
  7 255n8 cast printStack _:;
  targetNat: 255n8 dynamic;
  7 targetNat cast printStack _:;
  TRUE 0i16 cast printStack _:;
  TRUE -1i16 cast printStack _:;
  FALSE 0i16 cast printStack _:;
  FALSE -1i16 cast printStack _:;

  "-- whole to whole width and signedness --" printCompilerMessage
  -1 0n8 cast printStack _:;
  255n8 0i8 cast printStack _:;
  -1i8 0i16 cast printStack _:;
  255n8 0n16 cast printStack _:;

  "-- real to whole truncates toward zero --" printCompilerMessage
  7.9r32 0 cast printStack _:;
  -7.9r32 0 cast printStack _:;

  "-- unknown value --" printCompilerMessage
  value: 0 dynamic;
  value 123.0r32 cast printStack _:;

  0
] "main" exportFunction

Expected Output During Compilation

-- schema selector value ignored --
7n8
7n8
7n8
1i16
1i16
0i16
0i16
-- whole to whole width and signedness --
255n8
-1i8
-1i16
255n16
-- real to whole truncates toward zero --
7
-7
-- unknown value --
Real32

See also