Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Basics Swift Operators Operator Precedence

Math

I think the professional preparing this video is unaware of mathematic laws..

SivaKumar Kataru
SivaKumar Kataru
2,386 Points

No, He is Correct with All Known mathematic Laws . This is how an expressions is evaluated in traditional mathematics . Off course it might seem odd to You , but this is the way that compilers follow the rules of mathematics in evaluating the expression based on the precedence Level of the arithmetic operators . Remember some operators in expressions may be evaluated Either from Left to right / right to Left . But Arithmetic Operators Always starts evaluating from left to right only .

2 Answers

I mean the operands work like that in mathematics it is not the compiler's rule to take the multiplication and division operands prior to addition and subtraction. Thank you.

SivaKumar Kataru
SivaKumar Kataru
2,386 Points

Yes you are Right . Infact, Most of us haven't done evaluating a value of complex expressions in mathematics . When it comes to programming it is always the needy feature that programmer has to know it must .

What you are saying is true, however, Swift has the remainder operator which does not exist in the world of mathematics, so Swift needs its own rules.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Actually Saud Alfaris, that is incorrect.

The modulo operator is not just a function of Swift. It is used by almost every language and is a mathematical expression used in mathematics. You can read about it here if you wish. So, Swift is only following the rules of mathematics, not its own in this case.

:dizzy:

Actually, the teacher is aware of the mathematical laws. What do you mean?

SivaKumar Kataru
SivaKumar Kataru
2,386 Points

He is Aware of the rules of mathematics .