ในส่วนนี้เราจะเห็น lrint() และ llring() ใน C++ อันดับแรกให้เราพูดถึง lint().
ฟังก์ชัน lrint() ใช้เพื่อปัดเศษค่าที่กำหนดในอาร์กิวเมนต์ให้เป็นค่าปริพันธ์โดยใช้โหมดการปัดเศษปัจจุบัน โหมดปัจจุบันถูกกำหนดโดยใช้ fesetround().>=
ฟังก์ชัน lrint() นี้ใช้ค่า double หรือ float หรือ integer เป็นพารามิเตอร์อินพุต และส่งกลับค่า int แบบยาวโดยการปัดเศษส่วนที่เป็นส่วนสำคัญ
ตัวอย่าง
#include <cfenv>
#include <cmath>
#include <iostream>
using namespace std;
main() {
int x = 40;
long int res;
fesetround(FE_DOWNWARD); // setting rounding direction to DOWNWARD as downward
res = lrint(x);
cout << "Downward rounding of " << x << " is " << res << endl;
} ผลลัพธ์
Downward rounding of 40.0235 is 40
ฟังก์ชัน llrint() ใช้เพื่อปัดเศษค่าที่กำหนดในอาร์กิวเมนต์ให้เป็นค่าปริพันธ์โดยใช้โหมดการปัดเศษปัจจุบัน โหมดปัจจุบันถูกกำหนดโดยใช้ fesetround()
ฟังก์ชัน lrint() นี้ใช้ค่า double หรือ float หรือ integer เป็นพารามิเตอร์อินพุต และส่งกลับค่า long int ที่ยาวโดยการปัดเศษส่วนที่เป็นส่วนสำคัญ
ตัวอย่าง
#include <cfenv>
#include <cmath>
#include <iostream>
using namespace std;
main(){
double a;
long int res;
fesetround(FE_UPWARD); //set rounding direction to upward
a = 40.3;
res = llrint(a);
cout << "Upward rounding of " << a << " is " << res << endl;
fesetround(FE_DOWNWARD); //set rounding direction to downward
a = 40.88;
res = llrint(a);
cout << "Downward rounding of " << a << " is " << res << endl;
} ผลลัพธ์
Upward rounding of 40.3 is 41 Downward rounding of 40.88 is 40