Mul and Mul8 Command, Operator & Functions

Purpose

Multiplies a numeric variable with a numeric expression.

Syntax

Mul x, y( command)
% = i Mul j( operator)
% = Mul(i, j[,m,...])( function)

l = xl Mul8 yl( operator)
l = Mul8(xl, yl [,zl,…])( function)

x:any numeric variable
y:any numeric expression
i, j, m...:integer expression
l,xl,yl,zl...:large expression

Description

The command Mul x, j multiplies the value in the numeric variable x (integer or floating-point) with the expression j. The return value type depends on the type of the variable x.

The operator i Mul j and function Mul(i, j, …) multiply 32-bit integers and return a 32-bit integer value.

Similarly, the operator i Mul8 j and function Mul8(i, j, …) multiply 64-bit integers and return a 64-bit integer value.

Example

Debug.Show

Dim b# = 1.5, c As Large = 8

Trace b#

Trace b# Mul 3          // CInt(b#) * 3 = 6

Trace Mul(b#, 3)        // CInt(b#) * 3 = 6

Mul b#, 3 : Trace b#    // b# = 4.5

b# = 2.5 : Trace b#

Trace b# Mul 3          // CInt(b#) * 3 = 6

Trace Mul(b#, 3)        // CInt(b#) * 3 = 6

Mul b#, 3 : Trace b#    // b# = 7.5

Trace c

Trace c Mul8 3          // 24

Trace Mul8(c, 3)        // 24

Mul c, 3 : Trace c      // 24

Remarks

Although the command Mul can be used with any numeric variable, the usage of integer variables is recommended in order to achieve the maximum optimization for speed.

Instead of Mul x, y, you can use:

x = x * y

x := x * y

x *= y

When integer variables are used Mul doesn't test for overflow!

See Also

+, -, *, /, \, Add, Sub, Mod, Mul, Div, ++, --, +=, -=, /= , *=, Operator Hierarchy

{Created by Sjouke Hamstra; Last updated: 24/06/2017 by James Gaite}