ื›ื™ืชืช ืžืชืžื˜ื™ืงื” ืžื›ื™ืœื” ืฉื™ื˜ื•ืช ืœืขื‘ื•ื“ื” ืขื ืคื•ื ืงืฆื™ื•ืช ืžืชืžื˜ื™ื•ืช. ื‘ืžืืžืจ ื–ื”, ืื ื• ื”ื•ืœื›ื™ื ืœื“ื‘ืจ ืขืœ ืฉื™ื˜ืช Math.exp() ื‘-Java. ื”ื•ื ืžื—ื–ื™ืจ ืืช ื”ืžืกืคืจ e ืฉื”ื•ืขืœื” ื‘ื—ื–ืงืช ืขืจืš ื›ืคื•ืœ.

ืžื”ื™ ืคื•ื ืงืฆื™ื” ืืงืกืคื•ื ื ืฆื™ืืœื™ืช: ืžื‘ื•ื ืžืชืžื˜ื™ ืงืฆืจ ืžืื•ื“

ื”ืขืจื”: ืกืขื™ืฃ ื–ื” ืžืกื‘ื™ืจ ืืช ื”ืžืชืžื˜ื™ืงื” ืžืื—ื•ืจื™ ืฉื™ื˜ืช Math.exp() . ืื ืืชื ื›ื‘ืจ ื™ื•ื“ืขื™ื ื–ืืช, ืื• ืกืชื ืจื•ืฆื™ื ืœื”ืฉืชืžืฉ ื‘ืฉื™ื˜ื” ืžื‘ืœื™ ืœื”ื‘ื™ืŸ ืืช ื”ืžื”ื•ืช, ืืชื ืžื•ื–ืžื ื™ื ืœืขื‘ื•ืจ ืœื ืงื•ื“ื” ื”ื‘ืื”. ื”ืžืขืจื™ืš ื”ื•ื ื”ืคื•ื ืงืฆื™ื” y = e x , ื›ืืฉืจ e ื”ื•ื ืžืกืคืจ ืžืชืžื˜ื™ ืžืกื•ื‘ืš ืฉื”ื•ื ื‘ืขืจืš 2.718281828459045. ืžืกืคืจ ื–ื” ื—ืฉื•ื‘ ืœื ืคื—ื•ืช ืžืžืกืคืจ ื”-pi ื”ืžืคื•ืจืกื, ืืš ื”ื•ื ืžื•ื›ืจ ื‘ืขื™ืงืจ ืขืœ ื™ื“ื™ ืžืชืžื˜ื™ืงืื™ื, ืžืชื›ื ืชื™ื ื•ืื ืฉื™ื ื”ืขื•ื‘ื“ื™ื ืขื ืกื˜ื˜ื™ืกื˜ื™ืงื”. ืื’ื‘, ื™ืฉ ืœื–ื” ืฉื: ืžืกืคืจ ืื•ื™ืœืจ. ื’ื e ื”ื•ื ื”ื‘ืกื™ืก ืฉืœ ื”ืœื•ื’ืจื™ืชื ื”ื˜ื‘ืขื™. ืœื”ืœืŸ ื’ืจืฃ ื”ืคื•ื ืงืฆื™ื•ืช ื”ืืงืกืคื•ื ื ืฆื™ืืœื™ื•ืช: ืฉื™ื˜ืช Math.exp() ื‘-Java - 1ืœืชื”ืœื™ื›ื™ื ื”ืžืฆื™ื™ืชื™ื ืœื—ื•ืง ื”ืืงืกืคื•ื ื ืฆื™ืืœื™ ื™ืฉ ืžืืคื™ื™ืŸ ืžืฉื•ืชืฃ ืื—ื“: ื‘ืžืฉืš ืื•ืชื• ืžืจื•ื•ื— ื–ืžืŸ, ื”ืคืจืžื˜ืจื™ื ืฉืœื”ื ืžืฉืชื ื™ื ืื•ืชื• ืžืกืคืจ ืคืขืžื™ื. ืœืžืฉืœ, ืงื™ืจื•ืจ ืฉืœ ื ื•ื–ืœ: ื›ื›ืœ ืฉื”ืคืจืฉ ื”ื˜ืžืคืจื˜ื•ืจื” ื‘ื™ืŸ ืื•ื•ื™ืจ ืœื ื•ื–ืœ ื’ื“ื•ืœ ื™ื•ืชืจ, ื›ืš ื”ื•ื ืžืชืงืจืจ ืžื”ืจ ื™ื•ืชืจ. ื›ื›ืœ ืฉื›ื“ื•ืจ ื”ืฉืœื’ ื”ืžืชื’ืœื’ืœ ื‘ืžื•ืจื“ ื”ื”ืจ ื”ื•ืคืš ื’ื“ื•ืœ ื™ื•ืชืจ, ื›ืš ื”ื•ื ืžืชื’ืœื’ืœ ืžื”ืจ ื™ื•ืชืจ.

ืฉื™ื˜ืช Math.exp() ื‘-Java

ืขื›ืฉื™ื• ื‘ื•ืื• ื ื—ื–ื•ืจ ืœื’'ืื•ื•ื”. ืฉื™ื˜ืช double exp(double x) ืฉืœ ื”ืžื—ืœืงื” Math ืžื—ืฉื‘ืช ืืช ื”ืขืจืš ืฉืœ ืคื•ื ืงืฆื™ื™ืช ื”ืžืขืจื™ืš ื‘ื ืงื•ื“ื” x , ื‘ืžื™ืœื™ื ืื—ืจื•ืช, ื”ื™ื ืžื—ื–ื™ืจื” ืืช ื”ืžืกืคืจ e ื‘ื—ื–ืงืช x . ืœื™ืชืจ ื“ื™ื•ืง, ื”ื•ื ืžื—ื–ื™ืจ ืขืจืš ืžืฉื•ืขืจ ื‘ื“ื™ื•ืง ืžืกื•ื™ื. ืžื—ื–ื™ืจื” ืืช ื”ืžืกืคืจ e ืฉืœ ืื•ื™ืœืจ ืžื•ืจื ื‘ื—ื–ืงืช ืขืจืš ื›ืคื•ืœ. ื›ืœื•ืžืจ, Math.exp(2.0) = e 2.0 (ื–ื” ื‘ืขืจืš 7.34) ื”ื ื” ื”ืฆื”ืจื” ืขืœ ื”ืฉื™ื˜ื”:
double exp(double x)
ื›ืืฉืจ x ื”ื™ื ื”ืชื•ืืจ ืœื”ืขืœื•ืช ืืช ื”ืžืกืคืจ e . ื‘ื•ืื• ื ื™ืชืŸ ื“ื•ื’ืžื”.
public class ExpExample {
   public static void main(String[] args) {
       int x1 = 2;
       double x2 = 0.5;
       double x3 = 1;
       System.out.println("exponential function in  " + x1 + " = " + Math.exp(x1));
       System.out.println("exponential function in  " + x2 + " = " + Math.exp(x2));
       System.out.println("exponential function in  " + x3 + " = " + Math.exp(x3));
   }
}
ื”ืคืœื˜ ื”ื•ื:
ืคื•ื ืงืฆื™ื” ืืงืกืคื•ื ื ืฆื™ืืœื™ืช ื‘-2 = 7.38905609893065 ืคื•ื ืงืฆื™ื” ืžืขืจื™ื›ื™ืช ื‘-0.5 = 1.6487212707001282 ืคื•ื ืงืฆื™ื” ืžืขืจื™ื›ื™ืช ื‘-1.0 = 2.718281828459045

ื›ืžื” ืžืงืจื™ื ืžื™ื•ื—ื“ื™ื

ื‘ืžืชืžื˜ื™ืงื” ื™ืฉ ืžื•ืฉื’ื™ื ืฉืœ ืฆื•ืจื” ื‘ืœืชื™ ืžื•ื’ื“ืจืช, ื›ืžื• ื’ื ืื™ื ืกื•ืฃ ื—ื™ื•ื‘ื™ ื•ืฉืœื™ืœื™. ืžืกืคืจ ื—ื™ื•ื‘ื™ ื—ืœืงื™ 0.0 ื ื•ืชืŸ ืื™ื ืกื•ืฃ ื—ื™ื•ื‘ื™, ื•ืžืกืคืจ ืฉืœื™ืœื™ ื ื•ืชืŸ ืื™ื ืกื•ืฃ ืฉืœื™ืœื™. ืืชื” ื™ื›ื•ืœ ืœืงื‘ืœ ืฆื•ืจื” ื‘ืœืชื™ ืžื•ื’ื“ืจืช ื‘ื“ืจื›ื™ื ืฉื•ื ื•ืช. ืœื“ื•ื’ืžื”, ืื ืชื ืกื” ืœื—ืœืง ืืคืก ื‘ืืคืก ืื• ืื™ื ืกื•ืฃ ืœืื™ื ืกื•ืฃ. ื‘-Java ื™ืฉื ื ืงื‘ื•ืขื™ื ืžื™ื•ื—ื“ื™ื ืžื›ื™ืชื” Double ื›ื’ื•ืŸ Double.NaN (ืฆื•ืจื” ืžืขื˜ ื‘ืœืชื™ ืžื•ื’ื“ืจืช), Double.POSITIVE_INFINITY ื•- Double.NEGATIVE_INFINITY . ืฉื™ื˜ืช Math.exp() ืžืชื ื”ื’ืช ื‘ืฆื•ืจื” ืกืคืฆื™ืคื™ืช ื›ืืฉืจ ื”ื™ื ืžืชืžื•ื“ื“ืช ืขื ืฉืœื•ืฉืช ื”ืžื•ืฉื’ื™ื ื”ื‘ืื™ื:
  • ืื ื”ืืจื’ื•ืžื ื˜ ื”ื•ื NaN, ื”ืชื•ืฆืื” ื”ื™ื ื’ื NaN.
  • ืื ื”ื˜ื™ืขื•ืŸ ื”ื•ื ืื™ื ืกื•ืฃ ื—ื™ื•ื‘ื™, ืื– ื”ืชื•ืฆืื” ื”ื™ื ื’ื ืื™ื ืกื•ืฃ ื—ื™ื•ื‘ื™.
  • ืื ื”ืืจื’ื•ืžื ื˜ ื”ื•ื ืื™ื ืกื•ืฃ ืฉืœื™ืœื™, ืื– ื”ืชื•ืฆืื” ื”ื™ื ืืคืก ื—ื™ื•ื‘ื™.
ื”ื ื” ื“ื•ื’ืžื” ืœืงื•ื“ ืœืžืงืจื™ื ืžื™ื•ื—ื“ื™ื:
public class ExpSpecialCases {

   public static void main(String[] args) {

   double positiveInfinity = Double.POSITIVE_INFINITY;
   double negativeInfinity = Double.NEGATIVE_INFINITY;
   double nan = Double.NaN;

   //The argument is positive infinity, the output is positive infinity
       System.out.println(Math.exp(positiveInfinity));

   //The argument is negative infinity, the output is zero
       System.out.println(Math.exp(negativeInfinity));

   //The argument is NaN, the output is NaN
       System.out.println(Math.exp(nan));
}
}
ื”ืคืœื˜ ื”ื•ื:
ืื™ื ืกื•ืฃ 0.0 NaN