Rust in Action Notes Chapter 5 In-depth Understanding of Data

  1. If you want to see the f32 type number converted to the integer number u32 type, you need to call it under the unsafe package std::mem::transmute(data), because in the safe Rust syntax, there is no implementation of converting integer data into floating point data according to the bit. If you want to see the binary output of the floating point number (pass), you need to convert the floating point number into an integer number through unsafe before outputting {:b};
  2. The difference between big endian and little endian is that the high bit of the big endian notation is written first, for example, 123, the high bit is 1, the low bit is 3, the big endian notation is 123, the little endian notation is 321, and the high and low bits of the big and small endian are usually Byte;
  3. The composition of floating point numbers, sign bit (sign), effective number (mantissa), base number (base), exponent (exponent), Figure 5.1 shows the organization of a 32-bit floating point number;Figure 5.1
  4. The unary operator negative sign -has a lower priority than the method call, so when calling its method with a negative number, it must be wrapped in parentheses. For example, the logic of (-1.0)_f32.powf(0.0)and -1.0_f32.powf(0.0)is different. The former is ( − 1 ) 0 (-1)^0(1)0 while the latter is− ( 1 0 ) -(1^0)(10)
  5. PartialEqThe data can be ==compared by the equal sign, that is, only the values ​​need to be equal, and Eqthe data can be converted into any reasonable value for comparison, requiring the data to be equal at the bit level (there may be some representations that make different bitmap values ​​​​equal). The requirement ratio is more stringent, and the call of Eq can Eqbe PartialEqused person1.eq(&person2);
  6. For custom data implementation, std::convert::Fromcommon data types can be automatically converted into custom data, see Page155 for details;
  7. You can add prefixes to modules (mod), types (struct), enumerations (enum), etc. pubto make them public. There are many types of pub usage, which pub(crate)can be exposed to other modules of the entire crate, pub(super)only exposed to the parent module, pub(in path)only exposed to the specified path module, and pub(self)explicitly declare that the module is private (private);
  8. Section 5.7 implements a simple CPU function, including adder and multiplier, mainly related to instruction architecture and digital representation;

Guess you like

Origin blog.csdn.net/Mint2yx4/article/details/131167705