Jun 18, 2025
Оfftopic Community
Оfftopic Community
Forums
New posts
Search forums
What's new
Featured content
New posts
New media
New media comments
New resources
New profile posts
Latest activity
Media
New media
New comments
Search media
Resources
Latest reviews
Search resources
Members
Current visitors
New profile posts
Search profile posts
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
OffTopic Community
Introductions
C++ newbie: order of operations for * and /?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="jamess" data-source="post: 2643931" data-attributes="member: 216015"><p>The general laws of mathematics apply to most high-level programming languages, including C++, C#, Java, Perl, Python, etc.</p><p></p><p>The easiest way to remember it is by this acronym: BIMDAS</p><p></p><p>B //brackets always have priority, and as such are calculated first. Brackets inside of brackets are then again of higher priority, and this can regress infinitely.</p><p></p><p>I //indices; that is, powers, squares, square-roots, cubes, always have second priority</p><p></p><p>MD //multiplication and division. These are of the same priority, and are always calculated before addition and subtraction</p><p></p><p>AS //addition and subtraction - these are the last to be calculated</p><p></p><p>If there are two operands of equal priority in the same expression, they will usually be calculated left-to-right.</p><p></p><p>E.g. </p><p>2^2 * (4 * 3 / 2) + 55</p><p>= 4 * (12/2) + 55</p><p>= 4 * 6 + 55</p><p>= 24 + 55</p><p>= 79 </p><p></p><p>For your two expressions:</p><p></p><p>(1) x = y / (z) * 1.0e-3</p><p>is equivelent to: x = (y/z)*(1.0e-3)</p><p></p><p>(2) x = y/(z*1.0e-3)</p><p>is equivelent to: x=<img src="https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f44d.png" class="smilie smilie--emoji" loading="lazy" width="64" height="64" alt="(y)" title="Thumbs up (y)" data-smilie="22"data-shortname="(y)" /> / (z*(1.0e-3))</p></blockquote><p></p>
[QUOTE="jamess, post: 2643931, member: 216015"] The general laws of mathematics apply to most high-level programming languages, including C++, C#, Java, Perl, Python, etc. The easiest way to remember it is by this acronym: BIMDAS B //brackets always have priority, and as such are calculated first. Brackets inside of brackets are then again of higher priority, and this can regress infinitely. I //indices; that is, powers, squares, square-roots, cubes, always have second priority MD //multiplication and division. These are of the same priority, and are always calculated before addition and subtraction AS //addition and subtraction - these are the last to be calculated If there are two operands of equal priority in the same expression, they will usually be calculated left-to-right. E.g. 2^2 * (4 * 3 / 2) + 55 = 4 * (12/2) + 55 = 4 * 6 + 55 = 24 + 55 = 79 For your two expressions: (1) x = y / (z) * 1.0e-3 is equivelent to: x = (y/z)*(1.0e-3) (2) x = y/(z*1.0e-3) is equivelent to: x=(y) / (z*(1.0e-3)) [/QUOTE]
Insert quotes…
Name
Verification
Please enable JavaScript to continue.
Loading…
Post reply
Top