M Programming: A Comprehensive Guide

Chapter 4: Operations on Numeric Values

Chapter 4: Operations on Numeric Values
Note to Experienced Programmers
The M arithmetic operators are similar to those of most other languages. However, it may be valuable to review the operation of the modulo operator (#), operator precedence (not like other high-level programming languages!), the $RANDOM function, and the $HOROLOG special variable, since these features differ from similar operators in many other languages.
In Chapter 3 we learned that M recognizes only one type of data, a string, but that it can operate on numeric strings to produce valid numeric results. Since there is only one data type, a given variable can hold either numeric or text data, or both. Redefinition of a M variable, including changing back and forth between text and numbers, is perfectly acceptable in this language. You also learned that both types can be stored in the same variable at different times. This chapter introduces the types of operations that can be performed on numeric values; later, we will learn about other operations affecting strings as well as numbers. Most of the concepts used in M should already be familiar, since these ideas are really ones that you learned in elementary arithmetic.
Binary operators
M defines six operators that are used to combine numeric values in different ways (shown in the table on the next page). The first four operators correspond to the four basic arithmetic operations used in everyday activities.
Operator
Function
Operator
Function
+
Addition
\
Integer quotient division
?
Subtraction
#
Modulo,...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Digital Panel Meters
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.