Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

ฟังก์ชัน expm1() ใน C++

ฟังก์ชัน expm1() คำนวณ e^x - 1 (ค่าความเป็นธรรมชาติยกกำลัง x ลบ 1) ให้ความแม่นยำสูงกว่าการคำนวณ exp(x) - 1 โดยตรงเมื่อ x ใกล้ศูนย์

นิพจน์ทางคณิตศาสตร์

expm1(x) = e^x - 1

รูปแบบ

float expm1(float x);

ตัวอย่างโค้ด

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int x = 10;
    float y = 8.28;
    cout << "The value of x : " << expm1(x);
    cout << "\nThe value of y : " << expm1(y);
    return 0;
}

ผลลัพธ์

The value of x : 22025.5
The value of y : 3943.19