Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Praktisk programmering og numeriske metoder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lucas Christesen Ahler
Praktisk programmering og numeriske metoder
Commits
1a181424
Commit
1a181424
authored
4 years ago
by
Lucas Christesen Ahler
Browse files
Options
Downloads
Patches
Plain Diff
Lecture 3 exercise
parent
477c7dcc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
exercises/lec3-math/Makefile
+29
-0
29 additions, 0 deletions
exercises/lec3-math/Makefile
exercises/lec3-math/math.c
+28
-0
28 additions, 0 deletions
exercises/lec3-math/math.c
exercises/lec3-math/precision.c
+14
-0
14 additions, 0 deletions
exercises/lec3-math/precision.c
with
71 additions
and
0 deletions
exercises/lec3-math/Makefile
0 → 100644
+
29
−
0
View file @
1a181424
CC
=
gcc
CFLAGS
=
-O
-std
=
gnu11
LDLIBS
=
-lm
default
:
outmath.txt outprecision.txt
cat
outmath.txt
cat
outprecision.txt
outmath.txt
:
math
./math
>
outmath.txt
outprecision.txt
:
precision
./precision
>
outprecision.txt
math
:
math.o
$(
CC
)
math.o
-o
math
$(
LDLIBS
)
math.o
:
math.c
$(
CC
)
$(
CFLAGS
)
-c
math.c
-o
math.o
precision
:
precision.o
$(
CC
)
precision.o
-o
precision
$(
LDLIBS
)
precision.o
:
precision.c
$(
CC
)
$(
CFLAGS
)
-c
precision.c
-o
precision.o
.PHONEY
:
clean
clean
:
$(
RM
)
outmath.txt outprecision.txt math math.o precision precision.o
This diff is collapsed.
Click to expand it.
exercises/lec3-math/math.c
0 → 100644
+
28
−
0
View file @
1a181424
#include
<math.h>
#include
<complex.h>
#include
<stdio.h>
int
main
()
{
double
gam
=
tgamma
(
5
);
printf
(
"Gamma function of 5 = %g
\n
"
,
gam
);
double
bes
=
j1
(
0
.
5
);
printf
(
"Bessel function of 0.5 = %g
\n
"
,
bes
);
double
complex
sqr
=
csqrt
(
-
2
);
printf
(
"Square root of -2 = %g + %gi
\n
"
,
creal
(
sqr
),
cimag
(
sqr
));
double
complex
eipi
=
cpow
(
M_E
,(
I
*
M_PI
));
printf
(
"e to the power i*pi = %g + %gi
\n
"
,
creal
(
eipi
),
cimag
(
eipi
));
double
complex
ei
=
cpow
(
M_E
,
I
);
printf
(
"e to the power i = %g + %gi
\n
"
,
creal
(
ei
),
cimag
(
ei
));
double
complex
ie
=
cpow
(
I
,
M_E
);
printf
(
"i to the power e = %g + %gi
\n
"
,
creal
(
ie
),
cimag
(
ie
));
double
complex
ii
=
cpow
(
I
,
I
);
printf
(
"i to the power i = %g + %gi
\n
"
,
creal
(
ii
),
cimag
(
ii
));
return
0
;
}
This diff is collapsed.
Click to expand it.
exercises/lec3-math/precision.c
0 → 100644
+
14
−
0
View file @
1a181424
#include
<stdio.h>
#include
<math.h>
int
main
(){
float
floa
=
1
.
f
/
9
;
double
doub
=
1
.
/
9
;
long
double
lodo
=
1
.
L
/
9
;
printf
(
"The precision of different variable types:
\n
"
);
printf
(
"Float: %.25g
\n
"
,
floa
);
printf
(
"Double: %.25lg
\n
"
,
doub
);
printf
(
"Long double: %.25Lg
\n
"
,
lodo
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment