Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
battle_c
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
Container registry
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
이장원
battle_c
Commits
0c4edf84
Commit
0c4edf84
authored
4 years ago
by
이장원
Browse files
Options
Downloads
Patches
Plain Diff
8.4
parent
2b8c6c5e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
0804/fx_s1516_double.h
+28
-0
28 additions, 0 deletions
0804/fx_s1516_double.h
0804/test.c
+31
-0
31 additions, 0 deletions
0804/test.c
with
59 additions
and
0 deletions
0804/fx_s1516_double.h
0 → 100644
+
28
−
0
View file @
0c4edf84
#pragma once
typedef
int
fx_s1516
;
#include
<stdio.h>
#define _USE_MATH_DEFINES
#include
<math.h>
#define P2_16 65536.0f
#define e M_E
#define fx_s1516_PI M_PI
#define fx_s1516_INVERSE_PI 1/M_PI
#define degree_to_radian(a) ((a) * M_PI / 180)
#define fx_to_double(a) ((double)(a) / P2_16)
#define double_to_fx(a) ((a) * P2_16)
#define fx_s1516_add(a, b) double_to_fx((a) + (b))
#define fx_s1516_sub(a, b) double_to_fx((a) - (b))
#define fx_s1516_mul(a, b) double_to_fx((a) * (b) * P2_16)
#define fx_s1516_div(a, b) double_to_fx((a) / (b) / P2_16)
#define fx_s1516_sin(a) double_to_fx(sin(a * P2_16) / (P2_16))
#define fx_s1516_sqrt(a) double_to_fx(sqrt(a) / sqrt(P2_16))
#define fx_s1516_pow(a, b) double_to_fx(pow(a, (double)b) * pow(P2_16, (double)b - 1))
#define fx_s1516_log(a, b) double_to_fx(baselog(a * P2_16, b) / (P2_16))
double
baselog
(
double
a
,
double
base
)
{
return
log
(
a
)
/
log
(
base
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
0804/test.c
0 → 100644
+
31
−
0
View file @
0c4edf84
#
include
"fx_s1516_double.h"
/*
make first prototype fx_sxxyy_double.c with double and math.h
define macro fx_sxxyy_double.h program test.c
*/
int
main
()
{
fx_s1516
a
=
131072
;
fx_s1516
b
=
65536
;
double
fa
=
fx_to_double
(
a
);
double
fb
=
fx_to_double
(
b
);
printf
(
"a : %d b : %d fa : %lf fb : %lf
\n
original a : %lf original b : %lf
\n\n
"
,
a
,
b
,
fa
,
fb
,
double_to_fx
(
fa
),
double_to_fx
(
fb
));
printf
(
"add : %-15d %lf
\n
"
,
a
+
b
,
fx_s1516_add
(
fa
,
fb
));
printf
(
"sub : %-15d %lf
\n
"
,
a
-
b
,
fx_s1516_sub
(
fa
,
fb
));
printf
(
"mul : %-15lld %lf
\n
"
,
(
long
long
)
a
*
b
,
fx_s1516_mul
(
fa
,
fb
));
printf
(
"div : %-15lf %lf
\n\n
"
,
(
double
)
a
/
b
,
fx_s1516_div
(
fa
,
fb
));
printf
(
"sin : %-15lf %lf
\n
"
,
sin
(
degree_to_radian
(
a
)),
fx_s1516_sin
(
degree_to_radian
(
fa
)));
printf
(
"sqrt : %-15lf %lf
\n
"
,
sqrt
(
a
),
fx_s1516_sqrt
(
fa
));
printf
(
"sqrt : %-15lf %lf
\n
"
,
sqrt
(
b
),
fx_s1516_sqrt
(
fb
));
printf
(
"pow : %-15lld %lf
\n
"
,
(
long
long
)
pow
(
a
,
2
),
fx_s1516_pow
(
fa
,
2
));
printf
(
"log : %-15lf %lf
\n\n
"
,
baselog
(
a
,
e
),
fx_s1516_log
(
fa
,
e
));
printf
(
"pi : %f
\n
"
,
fx_s1516_pi
);
printf
(
"inverse pi : %f
\n
"
,
fx_s1516_inverse_pi
);
}
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