ฟังก์ชัน bcpowmod() ใช้ยกเลขฐาน (base) arbitrary precision ไปยังเลขชี้กำลัง (exponent) แล้วทำ modulo ด้วย modulus ที่ระบุ รับค่า 3 ตัวเป็น string คืนค่าผลลัพธ์หลังปัดเศษตาม precision
รูปแบบการใช้งาน (Syntax)
string|false bcpowmod(string $base, string $exponent, string $modulus, int $scale = 0)
พารามิเตอร์
- $base – เลขฐาน (left operand) string
- $exponent – เลขชี้กำลัง (right operand) string
- $modulus – modulus string
- $scale – จำนวนหลักทศนิยมในผลลัพธ์ (default 0)
ค่าที่คืนกลับ
คืนผลลัพธ์เป็น string คืน false หาก modulus เป็น 0 หรือ exponent เป็นค่าลบ
ตัวอย่าง 1: ไม่ระบุ scale
<?php $base = "5"; $exponent = "7"; $mod = "7"; $result = bcpowmod($base, $exponent, $mod); echo "Output without scale: " . $result; ?>
ผลลัพธ์
Output without scale: 5
ตัวอย่าง 2: ระบุ scale = 4
<?php $base = "5"; $exponent = "7"; $mod = "7"; $scale = 4; $result = bcpowmod($base, $exponent, $mod, $scale); echo "Output with scale: " . $result; ?>
ผลลัพธ์
Output with scale: 5.0000