tag:blogger.com,1999:blog-36017112.post4705284044606741107..comments2015-10-16T08:36:09.446+01:00Comments on Featherweight Musings: Rust for C++ programmers - part 3: primitive types and operatorsNick Cameron.noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-36017112.post-68065448896113971092014-11-08T23:10:07.705+00:002014-11-08T23:10:07.705+00:00I tried to declare let y = 0b_1100_0011_1011_0001;...I tried to declare let y = 0b_1100_0011_1011_0001; but getting below error.<br /><br />a.rs:13:9: 13:35 error: cannot determine a type for this local variable: cannot determine the type of this integer; add a suffix to specify the type explicitly [E0102]<br />a.rs:13 let y = 0b_1100_0011_1011_0001;<br /><br />We need to explicitly add the type (add i suffix) e.g<br /><br /> let y = 0b_1100_0011_1011_0001i;Rohit Joshihttp://www.blogger.com/profile/17033322854798433501noreply@blogger.comtag:blogger.com,1999:blog-36017112.post-55283224442038790192014-04-24T18:04:52.210+01:002014-04-24T18:04:52.210+01:00Don't forget that you can write 5_u8 (in fact,...Don't forget that you can write 5_u8 (in fact, you can put _ in arbitrary places within a number, e.g., 1_000_000_u32). I find that much more readable.Niko Matsakishttp://www.blogger.com/profile/17747970382445176700noreply@blogger.comtag:blogger.com,1999:blog-36017112.post-40823773343681881182014-04-23T13:22:26.646+01:002014-04-23T13:22:26.646+01:00In Rust, it is not called the modulo operator but ...In Rust, it is not called the modulo operator but the remainder operator. If you evaluate (-15) % 10 you will get -5. So that is a little bit awful, but we're probably stuck with it. One of the reasons it is like this is to be compatible with what C does, but I think most people expect it to behave like modulo in C, too, so the world is a little buggier as a result.<br /><br />https://github.com/mozilla/rust/pull/5990Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-36017112.post-5189118846391537072014-04-23T09:16:42.910+01:002014-04-23T09:16:42.910+01:00in C++, the integer division (and thus the modulo)...in C++, the integer division (and thus the modulo) with negative numbers is implementation-defined, with a preference to round towards 0 (eg, -15 \ 10 == -1 and 15 % 10 == -5); while some other languages (like Python) give the mathematical answer -2 and 5. In Rust, how the operator behaves?Anonymousnoreply@blogger.com