C/sqrt: Różnice pomiędzy wersjami
Usunięta treść Dodana treść
m →Przykład użycia: format |
|||
Linia 20:
====podstawowe użycie====
<source lang="c">
#include <stdio.h> // printf▼
#include <math.h> // sqrt▼
gcc s.c -lm -Wall▼
./a.out▼
sqrt(2.0000000000000000) = 1.4142135623730951 ▼
▲#include <stdio.h> //
▲#include <math.h>
int main(){
double a = 2.0;▼
s= sqrt(a);▼
long double l = 2.0L;
printf(" sqrt(%.16f) = %.16f \n", a,s);▼
// wynik
double sd;
long double sl;
sl = sqrtl(l);
printf(" sqrt(%.18LF) = %.18LF \n", l, sl);
return 0;
Linia 40 ⟶ 44:
</source>
Kompilacja:
▲ gcc s.c -lm -Wall
Uruchomienie :
▲ ./a.out
Wynik :
▲ sqrt(2.0000000000000000) = 1.4142135623730951
sqrt(2.000000000000000000) = 1.414213562373095049
Porównanie z wynikami wyższej precyzji:
1.41421 35623 73095 04880 168872420969807856967187537694807317667973799 // truncated to 65 decimal places from wikipedia
1.41421 35623 73095 1 // using sqrt = double precision: error on 16 position after decinal point
1.41421 35623 73095 049 // using sqrt = usung long double precision: error on 18 position after decimal point
==== zakresy====
|