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

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

ฟังก์ชัน ldexp() คำนวณค่า: x * 2^exp โดยรับพารามิเตอร์ 2 ตัว คือ ค่าตัวเลขทศนิยม (Significand) และเลขชี้กำลัง (Exponent)

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

ldexp(x, exp) = x * 2^exp

รูปแบบ

float ldexp(float x, int exp);

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

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

int main() {
    float x = 28.8;
    int y = 3;
    cout << "The value : " << ldexp(x, y);
    return 0;
}

ผลลัพธ์

The value : 230.4

การคำนวณ: 28.8 × 2³ = 28.8 × 8 = 230.4