.Modelica.Math.isPowerOf2

Information

Syntax

Math.isPowerOf2(i);

Description

The function call "Math.isPowerOf2(i)" returns true, if the Integer input i is a power of 2. Otherwise the function returns false. The Integer input has to be >=1.

Example

  Integer i1 = 1;
  Integer i2 = 4;
  Integer i3 = 9;
  Boolean result;
algorithm
  result := Math.isPowerOf2(i1);     // = true 2^0
  result := Math.isPowerOf2(i2);     // = true 2^2
  result := Math.isPowerOf2(i3);     // = false

Interface

function isPowerOf2
  extends Modelica.Icons.Function;
  input Integer i(min = 1) "Integer scalar";
  output Boolean result "= true, if integer scalar is a power of 2";
end isPowerOf2;

Generated at 2024-04-26T18:16:04Z by OpenModelicaOpenModelica 1.22.3 using GenerateDoc.mos