30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

NaN is<br />

returned if xis a negative number.<br />

Remarks: A domain error occurs if x ≤0.<br />

Example: #include /* for logf */<br />

#include /* for printf, perror */<br />

#include /* for errno */<br />

int main(void)<br />

{<br />

float x, y;<br />

errno = 0;<br />

x = 2.0F;<br />

y = logf (x);<br />

if (errno)<br />

perror("Error");<br />

printf("The natural logarithm of %f is %f\n\n",<br />

x, y);<br />

errno = 0;<br />

x = 0.0F;<br />

y = logf (x);<br />

if (errno)<br />

perror("Error");<br />

printf("The natural logarithm of %f is %f\n\n",<br />

x, y);<br />

errno = 0;<br />

x = -2.0F;<br />

y = logf (x);<br />

if (errno)<br />

perror("Error");<br />

printf("The natural logarithm of %f is %f\n\n",<br />

x, y);<br />

}<br />

Output:<br />

The natural logarithm of2.000000 is 0.693147<br />

The natural logarithm of 0.000000 is -inf<br />

Error: domain error<br />

The natural logarithm of-2.000000 is nan<br />

Standard C Libraries with Math Functions<br />

2004 Microchip Technology Inc. DS51456B-page 353<br />

modf<br />

Đối số: Xbase<br />

yexponent<br />

Quay trở lại giá trị: Trả về xraised cho y sức mạnh (x ^ y).<br />

Ghi chú: Nếu YIS 0 powfreturns 1 Nếu XIS 0.0 và YIS nhỏ hơn 0 powfreturns<br />

infand một lỗi miền xảy ra. Nếu tràn kết quả hoặc underflows, một<br />

phạm vi lỗi xảy ra.<br />

Ví dụ: # include / * Cho powf * /<br />

# include / * Cho printf, perror * /<br />

# include / * Cho errno * /<br />

int main (void)<br />

{<br />

nổi x, y, z;<br />

errno = 0;<br />

x = -2.0F;<br />

y = 3.0F;<br />

z = powf (x, y);<br />

if (errno)<br />

perror ("Lỗi");<br />

printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />

errno = 0;<br />

x = 3.0F;<br />

y = -0.5F;<br />

z = powf (x, y);<br />

if (errno)<br />

perror ("Lỗi");<br />

printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />

errno = 0;<br />

x = 0.0f;<br />

y = -3.0F;<br />

z = powf (x, y);<br />

if (errno)<br />

perror ("Lỗi");<br />

printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />

}<br />

Đầu ra:<br />

-2,000000 Nâng lên 3,000000 là -8,000000<br />

3.000000 nâng lên -,500000 là 0,577350<br />

Lỗi: lỗi miền<br />

0.000000 nâng lên -3,000000 là inf

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!