Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HDL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
RTSD
HDL
Commits
1dabc7a4
Commit
1dabc7a4
authored
7 years ago
by
Pieter Donker
Browse files
Options
Downloads
Patches
Plain Diff
added nof_digits_int and changed int_to_str
parent
00535ea6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/base/common/src/vhdl/common_str_pkg.vhd
+27
-5
27 additions, 5 deletions
libraries/base/common/src/vhdl/common_str_pkg.vhd
with
27 additions
and
5 deletions
libraries/base/common/src/vhdl/common_str_pkg.vhd
+
27
−
5
View file @
1dabc7a4
...
...
@@ -31,6 +31,7 @@ PACKAGE common_str_pkg IS
TYPE
t_str_4_arr
IS
ARRAY
(
INTEGER
RANGE
<>
)
OF
STRING
(
1
TO
4
);
FUNCTION
nof_digits
(
number
:
NATURAL
)
RETURN
NATURAL
;
FUNCTION
nof_digits_int
(
number
:
INTEGER
)
RETURN
NATURAL
;
FUNCTION
time_to_str
(
in_time
:
TIME
)
RETURN
STRING
;
FUNCTION
str_to_time
(
in_str
:
STRING
)
RETURN
TIME
;
...
...
@@ -70,6 +71,27 @@ PACKAGE BODY common_str_pkg IS
END
IF
;
END
;
FUNCTION
nof_digits_int
(
number
:
INTEGER
)
RETURN
NATURAL
IS
-- Returns number of digits in a natural number. Only used in string processing, so defined here.
-- log10(0) is not allowed so:
-- . nof_digits(0) = 1
-- We're adding 1 so:
-- . nof_digits(1) = 1
-- . nof_digits(9) = 1
-- . nof_digits(10) = 2
-- . nof_digits(1) = 2
BEGIN
IF
number
=
0
THEN
RETURN
1
;
ELSE
IF
number
>
0
THEN
RETURN
floor_log10
(
number
)
+
1
;
ELSE
RETURN
floor_log10
(
-1
*
number
)
+
2
;
END
IF
;
END
IF
;
END
;
FUNCTION
time_to_str
(
in_time
:
TIME
)
RETURN
STRING
IS
CONSTANT
c_max_len_time
:
NATURAL
:
=
20
;
VARIABLE
v_line
:
LINE
;
...
...
@@ -181,12 +203,12 @@ PACKAGE BODY common_str_pkg IS
FUNCTION
int_to_str
(
int
:
INTEGER
)
RETURN
STRING
IS
-- CONSTANT c_max_len_int : NATURAL := 20;
VARIABLE
v_line
:
LINE
;
VARIABLE
v_str
:
STRING
(
1
TO
nof_digits
(
int
)):
=
(
OTHERS
=>
' '
);
VARIABLE
v_line
:
LINE
;
VARIABLE
v_str
:
STRING
(
1
TO
nof_digits
_int
(
int
)):
=
(
OTHERS
=>
' '
);
BEGIN
STD
.
TEXTIO
.
WRITE
(
v_line
,
int
);
v_str
(
v_line
.
ALL
'RANGE
)
:
=
v_line
.
ALL
;
deallocate
(
v_line
);
STD
.
TEXTIO
.
WRITE
(
v_line
,
int
);
v_str
(
v_line
.
ALL
'RANGE
)
:
=
v_line
.
ALL
;
deallocate
(
v_line
);
RETURN
v_str
;
END
;
...
...
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