islessgreater() ตรวจสอบว่าอากิวเมนต์แรก น้อยกว่า หรือ มากกว่า อากิวเมนต์ที่สอง (ไม่รวมเท่ากัน) ประกาศใน <math.h> (C) / <cmath> (C++) ส่งคืน bool
รูปแบบ
bool islessgreater(value1, value2);
เทียบเท่า: (value1 > value2) || (value1 < value2)
ตัวอย่าง 1: ค่าต่างกัน
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int val1 = 28;
int val2 = 8;
bool result = islessgreater(val1, val2);
cout << "val1 islessgreater than val2 : " << result << endl;
return 0;
}
ผลลัพธ์
val1 islessgreater than val2 : 1
ตัวอย่าง 2: ค่าเท่ากัน
int val1 = 8, val2 = 8;
bool result = islessgreater(val1, val2);
cout << "val1 islessgreater than val2 : " << result << endl;
ผลลัพธ์
val1 islessgreater than val2 : 0
ฟังก์ชันเปรียบเทียบ Floating-point อื่นๆ
isless(x, y)− x < yisgreater(x, y)− x > yislessequal(x, y)− x ≤ yisgreaterequal(x, y)− x ≥ yisunordered(x, y)− x หรือ y เป็น NaN
ฟังก์ชันเหล่านี้ปลอดภัยกว่า Operator ธรรมดา เพราะไม่ยก Exception เมื่อเจอ NaN