++/C     
 


,     C++   .        :   abs  -,     .       ,  ,      :  5 / 2  2,  0.1 + 0.2   0.3   sin(90)     .

      :  C++,  C++20/23 (format, print, ranges, , constexpr)   C.     ,     ,    C  C++.    .

 ,           .   ,    ,    ,    cmath.





 

++/C     



C++    

   C++  C:    C++23,  ,   

Table of Contents






:     



        C++    abs  -,        ,    .

  ,     ,      .       . ,     double  ==      .




 


    C++20: g++ 10+, clang 12+  MSVC 2019+.

 .  .

   .   ,         : ,   .




  


      <cmath>.     <numeric>,    <numbers>,    <random>.








:








 -Wall -Wextra     ,      .  .




    C


          C:    <math.h>.         C,  ,  C       .








 -lm   .       undefined reference to sqrt   .  -std=c2x    C23 (     -std=c23).




   C++


     C++:    ,    C++20  C++23  std::format, std::print, ranges, , constexpr.      .  C++23    -std=c++23 (g++ 14+  clang 18+).




 ,    


  std::  .   abs(-2.5)      C   2. , ?  .

   ,    .     .

double   . 0.1 + 0.2 != 0.3,    ,    .




 1. ,     



  : 5 / 2  C++  2,        .   .




1.1. : abs  fabs


     .  ,    .








: std::abs(INT_MIN)   .  int  ?2147483648,   2147483647.      ,      ,   .




1.2. :   


        .  ,     .








  : double avg = sum / count;,    int.   ,   double  .      .




1.3. : %, fmod, remainder


 %    .      .








    std::fmod (   )  std::remainder (  ,   ):








  ,   0  m?1?  :








    ,    ,    .




1.4. 


int  .       ,        .








:         long long   ,   .




1.5.  C++:     


        .   -1    4294967295,  -1 < 1u  . C++20  ,   -:








:     int  unsigned (, i < v.size()),    ,   std::cmp_less.




1.6.   C


 C  std::    .      : abs  int, labs  long, llabs  long long (   <stdlib.h>)  fabs  double ( <math.h>).      .

  C23   <stdckdint.h>    ( gcc 14+  clang 18+).   true,    :











   1


 ,            .   3  4    3.5,   3.

   (, 100000).     :::,   /  %.

  ( 2,    0).      n    n  ?   mod   1.3,   n = 100.

 std::abs(-2.7)  #include <cmath>   2?        .

    1  100000  int   long long.     .




 2.   : pow, sqrt, cbrt, hypot



 : pow  ,    ;    x * x,    sqrt,     hypot.




2.1. pow    


 C++   ^  . 2 ^ 3    XOR,    1.        .








  : pow  double. (int)std::pow(10, 2)      99,    99.9999999.      :








     .       .




2.2. sqrt  cbrt  









: cbrt    ,  pow(x, 1.0/3)  .     cbrt.

         - :











2.3. hypot    


    :










  sqrt(a*a + b*b)?    a = 1e200    ,  hypot  .   .




:    












2.4.  C++:    


 ipow   constexpr         .   std::integral     double:








static_assert   ,    .       .  C++26   constexpr    <cmath>,  sqrt  pow.




2.5.   C


      : sqrtf  float, sqrt  double, sqrtl  long double.    ,  <tgmath.h>    :        .











   2


 2 ^ 3  std::pow(2, 3). ,   .

 ipow   2  62- .   std::pow(2.0, 62)      ?

  :  a, b, c    .   :  , ,  .

    .      hypot.

     1  1000    isSquare.  ?




 3.   : log, exp   



 :         ,   ,  log  C++    ,   .




3.1.     


 2  10- = 1024,   1024   2  10. .       ,  .



     .     1000000 ? log2(1000000) ? 20.      .




  .


   .

   ,     (https://www.litres.ru/book/aleksey-primak/s-c-i-matematika-bez-soplei-kod-74635997/)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


