neg

neg (value -- negatedValue)

Inputs

Outputs

neg accepts signed Int schemas and Real schemas. The input is dereferenced and must be non-NIL.

This is arithmetic negation, not bitwise complement. The Whole or Real value is mapped to its additive inverse.

Bitwise complement is provided by ~.

Behavior

Example

{} () {} [
  "-- int32 --" printCompilerMessage
  7 neg printStack _:;
  -7 neg printStack _:;

  "-- neg versus ~ --" printCompilerMessage
  5 neg printStack _:;
  5 ~ printStack _:;

  "-- real32 --" printCompilerMessage
  2.5r32 neg printStack _:;
  -2.5r32 neg printStack _:;

  "-- unknown real32 --" printCompilerMessage
  value: 0.0r32 dynamic;
  value neg printStack _:;
] "main" exportFunction

Expected Output During Compilation

-- int32 --
-7
7
-- neg versus ~ --
-5
-6
-- real32 --
-2.5r32
2.5r32
-- unknown real32 --
Real32

See also