Python의 소수 함수 | 세트 1

Python의 정의에서는 'decimal' 모듈을 사용하여 더 빠른 십진 부동 소수점 연산을 수행하는 특정 방법을 제공합니다. 
소수에 대한 중요한 작업
1. sqrt() :- 이 함수는 제곱근 십진수의.
2. 특급() :- 이 함수는 e^x(지수) 십진수의.
 

Python
   # Python code to demonstrate the working of    # sqrt() and exp()   # importing 'decimal' module to use decimal functions   import   decimal   # using exp() to compute the exponent of decimal number   a   =   decimal  .  Decimal  (  4.5  )  .  exp  ()   # using sqrt() to compute the square root of decimal number   b   =   decimal  .  Decimal  (  4.5  )  .  sqrt  ()   # printing the exponent   print   (  'The exponent of decimal number is : '    end  =  ''  )   print   (  a  )   # printing the square root   print   (  'The square root of decimal number is : '    end  =  ''  )   print   (  b  )   

산출: 

 The exponent of decimal number is : 90.01713130052181355011545675   
The square root of decimal number is : 2.121320343559642573202533086


3. ln() :- 이 함수는 계산에 사용됩니다. 자연로그 십진수의.
4. 로그10() :- 이 함수는 계산에 사용됩니다. 로그(기본 10) 십진수의.
 

Python
   # Python code to demonstrate the working of    # ln() and log10()   # importing 'decimal' module to use decimal functions   import   decimal   # using ln() to compute the natural log of decimal number   a   =   decimal  .  Decimal  (  4.5  )  .  ln  ()   # using sqrt() to compute the log10 of decimal number   b   =   decimal  .  Decimal  (  4.5  )  .  log10  ()   # printing the natural logarithm   print   (  'The natural logarithm of decimal number is : '    end  =  ''  )   print   (  a  )   # printing the log10   print   (  'The log(base 10) of decimal number is : '    end  =  ''  )   print   (  b  )   

산출: 

 The natural logarithm of decimal number is : 1.504077396776274073373258352   
The log(base 10) of decimal number is : 0.6532125137753436793763169118


5. as_tuple() :- 다음을 포함하는 튜플로 십진수를 반환합니다. 3개의 인수 부호(0은 + 1은 -) 숫자 및 지수 값 .
6. fma(ab) :- 이 'fma'는 다음을 의미합니다. 융합된 곱셈과 더하기 . 그것은 계산한다 (숫자*a)+b 논쟁의 숫자로부터. (num*a) 반올림 없음 이 기능에서 발생합니다.
예 :  
 

 decimal.Decimal(5).fma(23) --> (5*2)+3 = 13  


 

Python
   # Python code to demonstrate the working of    # as_tuple() and fma()   # importing 'decimal' module to use decimal functions   import   decimal   # using as_tuple() to return decimal number as tuple   a   =   decimal  .  Decimal  (  -  4.5  )  .  as_tuple  ()   # using fma() to compute fused multiply and addition   b   =   decimal  .  Decimal  (  5  )  .  fma  (  2    3  )   # printing the tuple   print   (  'The tuple form of decimal number is : '    end  =  ''  )   print   (  a  )   # printing the fused multiple and addition   print   (  'The fused multiply and addition of decimal number is : '    end  =  ''  )   print   (  b  )   

산출: 

 The tuple form of decimal number is : DecimalTuple(sign=1 digits=(4 5) exponent=-1)   
The fused multiply and addition of decimal number is : 13


7. 비교() :- 이 함수는 십진수를 비교하는 데 사용됩니다. 첫 번째 10진수 인수가 두 번째 인수보다 크면 1을 반환하고, 첫 번째 10진수 인수가 두 번째 인수보다 작으면 -1을 반환하고 둘 다 같으면 0을 반환합니다.
8. 비교_총_매그() :- 십진수의 총 크기를 비교합니다. 첫 번째 10진수 인수가 2번째(부호 무시)보다 크면 1을 반환하고, 첫 번째 10진수 인수가 2번째(부호 무시)보다 작으면 -1을 반환하고 둘 다 같으면(부호 무시) 0을 반환합니다.
 

Python
   # Python code to demonstrate the working of    # compare() and compare_total_mag()   # importing 'decimal' module to use decimal functions   import   decimal   # Initializing decimal number   a   =   decimal  .  Decimal  (  9.53  )   # Initializing decimal number   b   =   decimal  .  Decimal  (  -  9.56  )   # comparing decimal numbers using compare()   print   (  'The result of comparison using compare() is : '    end  =  ''  )   print   (  a  .  compare  (  b  ))   # comparing decimal numbers using compare_total_mag()   print   (  'The result of comparison using compare_total_mag() is : '    end  =  ''  )   print   (  a  .  compare_total_mag  (  b  ))   

산출: 

 The result of comparison using compare() is : 1   
The result of comparison using compare_total_mag() is : -1


9. 복사_abs() :- 이 함수는 다음을 인쇄합니다. 순수한 소수 인수의 값입니다.
10. 복사_부정() :- 이 함수는 다음을 인쇄합니다. 부정 소수 인수.
11. 복사_사인() :- 이 함수는 다음을 인쇄합니다. 두 번째 인수의 부호를 복사하여 첫 번째 인수 .
 

Python
   # Python code to demonstrate the working of    # copy_abs()copy_sign() and copy_negate()   # importing 'decimal' module to use decimal functions   import   decimal   # Initializing decimal number   a   =   decimal  .  Decimal  (  9.53  )   # Initializing decimal number   b   =   decimal  .  Decimal  (  -  9.56  )   # printing absolute value using copy_abs()   print   (  'The absolute value using copy_abs() is : '    end  =  ''  )   print   (  b  .  copy_abs  ())   # printing negated value using copy_negate()   print   (  'The negated value using copy_negate() is : '    end  =  ''  )   print   (  b  .  copy_negate  ())   # printing sign effected value using copy_sign()   print   (  'The sign effected value using copy_sign() is : '    end  =  ''  )   print   (  a  .  copy_sign  (  b  ))   

산출: 

 The absolute value using copy_abs() is : 9.5600000000000004973799150320701301097869873046875   
The negated value using copy_negate() is : 9.5600000000000004973799150320701301097869873046875
The sign effected value using copy_sign() is : -9.5299999999999993605115378159098327159881591796875


12. 최대() :- 이 함수는 최고 두 개의 십진수 중.
13. 분() :- 이 함수는 최저한의 두 개의 십진수 중.
 

Python
   # Python code to demonstrate the working of    # min() and max()   # importing 'decimal' module to use decimal functions   import   decimal   # Initializing decimal number   a   =   decimal  .  Decimal  (  9.53  )   # Initializing decimal number   b   =   decimal  .  Decimal  (  7.43  )   # printing minimum of both values   print   (  'The minimum of two numbers is : '    end  =  ''  )   print   (  a  .  min  (  b  ))   # printing maximum of both values   print   (  'The maximum of two numbers is : '    end  =  ''  )   print   (  a  .  max  (  b  ))   

산출: 

 The minimum of two numbers is : 7.429999999999999715782905696   
The maximum of two numbers is : 9.529999999999999360511537816