1 <?xml version="1.0" encoding="UTF-8"?>
4 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
5 * Copyright (C) 2016 - Samuel GOUGEON
7 * Copyright (C) 2012 - 2016 - Scilab Enterprises
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
17 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
18 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml"
19 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
20 xmlns:scilab="http://www.scilab.org" xml:id="bitor" xml:lang="en">
22 <refname>bitor</refname>
23 <refpurpose>bitwise logical OR between element-wise integers of 2 arrays</refpurpose>
32 <title>Parameters</title>
38 scalars, vectors, matrices or hypermatrices of null or
39 positive integers encoded as decimal or integer numbers
40 of any signed or unsigned <link linkend="inttype">inttype</link>.
41 <warning>Sparse-encoded matrices are not accepted.</warning>
44 If <literal>u</literal> and <literal>v</literal> have
45 the same type and inttype, this one is the working one.
49 if <literal>u</literal> or <literal>v</literal>
50 is decimal-encoded, the working inttype is 0
51 (real decimal), even if the other operand
52 is int64- or uint64-encoded.
55 if <literal>u</literal> and <literal>v</literal>
56 are both encoded integers, the working inttype
57 is the widest of both: int8 < uint8 <
58 int16 < uint16 < int32 < uint32 <
64 The result <literal>w</literal> gets the type of the
68 <literal>u</literal> and <literal>v</literal> are
69 processed element-wise:
72 If <literal>u</literal> is a single value (scalar)
73 and <literal>v</literal> is a vector, matrix or
74 hypermatrix, <literal>u</literal> is priorly
75 expanded as <literal>u*ones(v)</literal> in order
76 to operate <literal>u</literal> with every
77 <literal>v</literal> component.
80 Conversely, <literal>v</literal> is priorly
81 expanded as <literal>v*ones(u)</literal> if it
85 If neither <literal>u</literal> nor <literal>v</literal>
86 are scalars, they must have the same sizes.
91 <literal>w</literal> gets the sizes of
92 <literal>u</literal> or/and <literal>v</literal>
100 <title>Description</title>
101 For each pair of components <literal>u(i)</literal> and <literal>v(i)</literal>,
102 <literal>bitor(u, v)</literal> computes and returns in <literal>w(i)</literal>
103 the bitwise OR conjunction of <literal>u(i)</literal> and <literal>v(i)</literal>
106 With encoded integers, <literal>bitor(u, v)</literal> is equivalent
107 to <literal>u | v</literal>. However, <literal>u | v</literal>
108 demands that <literal>u</literal> and <literal>v</literal> have
109 the same inttype, while <literal>bitor(..)</literal> accepts
113 For any decimal integer <literal>u</literal> greater than 2^52,
114 only its bits from log2(u) down to log2(u)-52 are encoded and can
115 be actually taken into account. Lower bits are not stored and are
120 <title>Examples</title>
121 <programlisting role="example"><![CDATA[
123 dec2bin([25 33 57]') // binary representations
125 <screen><![CDATA[--> bitor(25, 33)
129 --> dec2bin([25 33 57]'))
136 <programlisting role="example"><![CDATA[
137 // Between 2 simple rows with zeros and ones
140 bitor(u, v) // [0 1 1 1] expected
142 // Encoded integers such as int8 are accepted:
147 // Operands of mixed types are accepted.
148 // The type of the result is decimal if a decimal operand is involved,
149 // or the widest integer one otherwise:
152 z = bitor(u, int64(v)); type(z) // 1 : decimal representation
153 z = bitor(uint8(u), int8(v)); typeof(z) // uint8
154 z = bitor(uint8(u), int32(v)); typeof(z) // int32
156 // Usage with 2 matrices
161 bitor(u, v) // [ 3 6 12 24 ; 57 57 57 57 ] expected
163 // Usage with a distributed scalar:
164 bitor([1 2 4 8 9 10 12], 8) // == bitor([1 2 4 8 9 10 12], [8 8 8 8 8 8 8])
165 bitor(4, [1 2 4 8 9 10 12]) // == bitor([4 4 4 4 4 4 4], [1 2 4 8 9 10 12])
168 <programlisting role="example"><![CDATA[
169 // With encoded integers, bitor(u,v) and u|v are equivalent:
172 [bitor(u, v) ; u | v]
173 // ... but "|" demands operands with the same type:
174 u | 6 // mismatching int8- | decimal- encodings
176 <screen><![CDATA[--> u = int8([2 3 10]);
178 --> [bitor(u, v) ; u | v]
183 Undefined operation for the given operands.
184 check or define function %i_g_s for overloading.
187 <programlisting role="example"><![CDATA[
188 // Examples with big decimal integers:
190 u = sum(2 .^(600+[0 3 9 20 45])) // ~ 1.46D+194
191 v = 2^630 // ~ 4.46D+189
193 w == (u+v) // must be true, since u is built without the bit #630
194 bitor(u, 2^645) == u // true, since u has already its bit #645 set to 1
195 bitor(u, 2^601) == u // false
197 n = fix(log2(u)) // Index of the heaviest bit of u
198 bitor(u, 2^(n-52)) == u // false: The lightest bit of u was at 0 => This changes it
199 bitor(u, 2^(n-53)) == u // true: Addressing bits below the lightest doesn't change u
202 <refsection role="see also">
203 <title>See also</title>
204 <simplelist type="inline">
206 <link linkend="or_op">|</link>
209 <link linkend="or">or</link>
212 <link linkend="bitxor">bitxor</link>
215 <link linkend="bitand">bitand</link>
218 <link linkend="dec2bin">dec2bin</link>
222 <refsection role="history">
223 <title>History</title>
226 <revnumber>6.0</revnumber>
230 Extension to positive signed encoded integers
233 Extension to new int64 and uint64 inttypes
236 Operands of mixed types or inttypes are now accepted.
239 bitor(scalar, array) and bitor(array, scalar) are now supported.
242 Extension to decimal numbers greater than
243 2^32 and even than 2^52,
244 up to 1.80D+308 (== number_properties("huge")), for
245 the 52 heaviest encoded bits of their unsigned mantissa.