neg (object -- negatedValue)
Inputs
Outputs
negatedValue: Negated object in the same schema.
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 Int or Real object is mapped to its additive inverse.
Bitwise complement is provided by ~.
Behavior
- A known input is negated at compile time.
- An unknown input produces an object with an unknown value of the same schema.
- Nat is invalid because arithmetic negation is defined here only for signed Int and Real.
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
^builtin(base exponent -- power)Raises one Real object to another of the same schema and keeps that real schema in the result.castbuiltin(object schema -- convertedValue)Casts a Cond or numeric object to the numeric schema selected by theschemainput.ceilbuiltin(object -- ceilingValue)Rounds a Real object upward and keeps the same real schema.cosbuiltin(angle -- cosine)Computes the cosine of a Real object and keeps the same real schema.floorbuiltin(object -- floorValue)Rounds a Real object downward and keeps the same real schema.logbuiltin(argument -- naturalLogarithm)Computes the natural logarithm of a Real object and keeps the same real schema.log10builtin(argument -- decimalLogarithm)Computes the base-10 logarithm of a Real object and keeps the same real schema.sinbuiltin(angle -- sine)Computes the sine of a Real object and keeps the same real schema.sqrtbuiltin(radicand -- squareRoot)Computes the square root of a Real object and keeps the same real schema.