십진수의 수치적 구현은 부동 소수점 숫자입니다. C++ 프로그래밍 언어에서 float의 크기는 32비트입니다. 그리고 부동 소수점 숫자에서 작동하는 몇 가지 부동 소수점 조작 함수가 있습니다. 여기에서는 부동 소수점 조작 기능 중 일부를 소개했습니다.
fmod()
float에서 작동하는 fmod() 함수는 전달된 메서드 인수의 나머지 부분을 반환합니다.
예
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a, b, rem;
a = 23.4;
b = 4.1;
rem = fmod(a,b);
cout<<"The value of fmod( "<<a<<" , "<<b<<" ) = "<<rem;
}의 값 출력
The value of fmod( 23.4 , 4.1 ) = 2.9
나머지()
나머지() 함수는 fmod 함수와 동일한 작업을 수행합니다. 그리고 값 사이의 나눗셈의 나머지를 반환합니다. 이 메서드는 숫자 값의 관점에서 가능한 최소 나머지를 반환합니다. 부정적일 수도 있습니다.
예
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a, b, rem;
a = 23.4;
b = 4.1;
rem = remainder(a,b);
cout<<"The value of remainder( "<<a<<" , "<<b<<" ) = "<<rem;
} 출력
The value of remainder( 23.4 , 4.1 ) = -1.2
렘쿼()
이 메서드는 전달된 두 값의 몫과 나머지를 반환하며 몫 값을 가질 변수에 대한 참조도 필요합니다. 따라서 이 메서드는 나머지 함수와 몫의 참조와 동일한 나머지를 반환합니다.
예시
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a, b, rem;
int quo;
a = 23.4;
b = 4.1;
rem = remquo(a,b,&quo);
cout<<a<<" and "<<b<<" passed to the remquo() function gives the following output\n";
cout<<"The remainder is "<<rem<<endl;
cout<<"The quotient is "<<quo;
} 출력
23.4 and 4.1 pass to the the remque() function gives the following output The reminder is -1.2 The quotient is 6
카피부호()
C의 copysign 함수는 다른 변수의 부호가 있는 변수를 반환합니다. 반환된 변수는 첫 번째 변수의 크기와 두 번째 변수의 부호를 갖습니다.
예시
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a, b;
a = 9.6;
b = -3.5;
cout<<"copysign function with inputs "<<a<<" and "<<b<<" is "<<copysign(a,b);
} 출력
Copysign function with inputs 9.6 and -3.5 is -9.6
fmin()
fmin 함수는 이름에서 알 수 있듯이 함수의 두 인수 중 최소값을 반환합니다. 반환 유형은 float입니다.
예시
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a, b;
a = 43.5;
b = 21.2;
cout << "The smallest of "<<a<<" and "<<b<<" is "; cout << fmin(a,b)<<endl;
}
출력
The smallest of 43.5 and 21.2 is 21.2
fmax()
fmax 함수는 인수에 있는 두 숫자 중 가장 큰 숫자를 반환하는 C 프로그래밍 함수입니다.
예
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a, b;
a = 43.5;
b = 21.2;
cout << "The largest of "<<a<<" and "<<b<<" is "; cout << fmax(a,b)<<endl;
} 출력
The largest of 43.5 and 21.2 is 43.5
fdim()
C 프로그래밍 언어의 fdim() 함수는 함수에 대한 인수로 전송된 두 숫자의 절대 차이를 반환합니다.
예
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a, b;
a = 43.5;
b = 21.2;
cout << "The absolute difference of "<<a<<" and "<<b<<" is";
cout << fdim(a,b)<<endl;
} 출력
The absolute difference of 43.5 and 21.2 is 22.3
fma()
fma() C의 함수는 주어진 인수의 곱을 반환합니다. 이 함수는 부동 소수점을 반환하고 세 개의 부동 인수를 허용합니다.
예시
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a, b, c;
a = 3.5;
b = 2.4;
c = 7.2;
cout << "The multiplication of "<<a<<" , "<<b<<" and "<<c<<" is ";
cout << fma(a,b,c)<<endl;
} 출력
The multiplication of 3.5 , 2.4 and 7.2 is 15.6
다음은 플로팅을 통해 작동되는 모든 기능입니다. -point number. cmath 라이브러리에 정의된 함수입니다.