파이썬[Python]: math - fmod 함수

math 모듈 - fmod 함수(function)


/// 설명

C언어 라이브러리에 정의되어 있는 값을 반환합니다.(r = x - ny, n = x / y, sign = x's sign)
이 값은 파이썬의 x % y 와 다를 수 있습니다.

※ 형식
math.fmod(x, y)

reference
https://docs.python.org/3/library/math.html#module-math

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import math
 
# x > 0, y > 0 --------------- same result
# x > y
print(math.fmod(152))  # 1.0
print(15 % 2)  # 1
 
# x == y
print(math.fmod(1515))  # 0.0
print(15 % 15)  # 0
 
# x < y (remainder = x)
print(math.fmod(1520))  # 15.0
print(15 % 20)  # 15
 
# x < 0 or y < 0 ------------- I'm not sure
print(math.fmod(2-102))  # 2.0
print(2 % -102)  # -100
 
print(math.fmod(-2-2))  # -0.0
print(-2 % -2)  # 0
 
print(math.fmod(-2102))  # -2.0
print(-2 % 102)  # 100
 
print(math.fmod(-350-100))  # -50.0
print(-350 % -100)  # -50
 
# ...
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수