Merge pull request #244 from louisrubet/#195/version-2.4

generation of v2.4.0
This commit is contained in:
Louis Rubet 2022-02-28 17:51:00 +01:00 committed by GitHub
commit 60099e32cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 190 additions and 215 deletions

View file

@ -2,7 +2,7 @@ name: CMake
on:
pull_request:
branches: [ v2.4.0-devel ]
branches: [ v2.4.0-devel, master ]
env:
BUILD_TYPE: Release

55
CHANGELOG.md Normal file
View file

@ -0,0 +1,55 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.4.0] - 2022-02-28
### Added
- Better parser (in fact just a lexer, because that's all it takes).
- Use of [mpreal](http://www.holoborodko.com/pavel/mpfr/) instead of raw mpfr for calc on reals.
- Use of the standard C++ complex class.
- Enhanced code quality and memory usage checks.
- Added github actions to pass functional tests and valgrind mem checks at each pull request.
- Applied [google c++ style guide](https://google.github.io/styleguide/cppguide.html)
- points covered are very numerous: c++17, define guard, name and order of inclusions, static and global variables, common patterns, classes, naming conventions etc.
- cpplint used with a CPPLINT.cfg removing some warnings.
- clang-format is now based on google style.
- Test files are now markdown (.md) files, tests result are slightly changed.
- Delived as flatpak, not as rpm and deb anymore.
- Automatic version string from git.
- hex and bin numbers accept floating point input and C99 standard output.
- `«` and `»` are now valid as program delimiters. `<<` and `>>` are still valid.
- Entering the sign after the base (ex: 0x-1e2) is allowed.
- rpn is delivered as flatpak and snap packages to be compatible with a maximum of Linux distribs. rpm and deb are no longer generated.
### Changed
Be carefull, compatibility is broken on these points compared to last version 2.3.2:
- `<< <<` input doesn't lead to `««»»` but to `«<< »`, preventing to eval the real program content.
- Making an operation stick to the previous entry is not possible anymore (ex: `1 2+` instead of `1 2 +`), this corrects bad behaviors like `3b114` pushing `3b11` and `4`.
- Complexes are written in the form `(1,2)` instead of `(1, 2)` (space is removed).
- The binary prefix is always `0b` on display, but the input can be `0b`, `0B`, `2b` or `2B`.
- The hex prefix is always `0x` on display, but the input still can be `0x`, `0X` or `16B` at input.
- `mant` and `xpon` now give binary (and not decimal) significand and exponent, as it is the norm in the standard libs (libC, standard C++, mpfr, gmp).
- `dupn`, `roll`, `rolld` are not leaving anymore their argument in front of the stack in case of error.
- `sto+` `sto-` `sto*` `sto/` don't accept anymore the syntax `'varname' value stoX`, but only `value 'varname' stoX`, ex: `3 'a' sto*`.
- Incomplete entry `(1,` is not available anymore.
### Removed
- Removed useless `unti`, `repea`, `whil` (prev. existing for HP28S compatibility).
- Removed `sqr` function, please use `sq` instead (prev. existing for HP28S compatibility).
- Removed CtrlC for interrupting a program (considered useless).
- Removed old memory management, efficient but poorly maintainable.
- Removed man page generation.
### Fixed
- `sub` now only accepts boundaries between 1 and the string length.
- `sto/` behavior: sto/ now correctly stores variable divided by constant and not constant divided by variable.
- `cosh` now returns the hyp cosinus instead of the hyp sinus.

View file

@ -2,7 +2,7 @@
project(rpn)
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.16)
if((NOT CMAKE_BUILD_TYPE MATCHES Debug)
AND (NOT CMAKE_BUILD_TYPE MATCHES Release))
@ -19,7 +19,6 @@ else(EXISTS ${PROJECT_SOURCE_DIR}/.git)
endif()
add_definitions(-DGIT_VERSION="${GIT_VERSION}")
message("GIT_VERSION is ${GIT_VERSION}")
message("GIT_VERSION is ${GIT_VERSION}")
# INFO
set(RPN_DISPLAY_NAME "rpn")
@ -92,13 +91,5 @@ add_executable(rpn ${RPN_SRC_FILES} ${LINENOISE_NG_SRC_FILES})
target_link_libraries(rpn mpfr)
target_link_libraries(rpn gmp)
# man
add_custom_target(man ALL)
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/doc/rpn.1.gz
COMMAND gzip -f -k ${PROJECT_SOURCE_DIR}/doc/rpn.1
)
# install
install(TARGETS rpn DESTINATION bin)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/rpn.1.gz DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1)

View file

@ -1,52 +0,0 @@
Changelog
- Better parser (now called lexer)
- Use of mpreal instead of raw mpfr for calc on reals
- Use of C++ complex class
- Removing old memory management, efficient but poorly maintainable
- Enhanced code quality and memory usage checks
- Added CircleCI checks: passing functional tests and valgrind mem checks at each pull request
- SonarCloud integration, Sonar way profile
- clang-format now based on google style
- [google c++ style guide](https://google.github.io/styleguide/cppguide.html) applied
- c++17
- define guard
- name and order of inclusions
- static and global variables
- common patterns (ex: no static maps or vectors)
- classes (explicit)
- naming:
- file names (.cc .h), types (PascalCase), variables (snake_case), members (trailing _), static const (camelCase begining with k), enum (enum class, values like static const
- consistent comments (//), class comments, functions comments
- cpplint used with a CPPLINT.cfg removing some warnings
- Test files are now markdown (.md) files, tests result are slightly changed
- Delivery as flatpak and snap
- error string are slightly different, althought error codes are still the same
- automatic version string from git, slightly change from previous versions
- hex and bin numbers accept floating point inputs
- std, fix and sci don't apply to hex and bin
New
- `«` and `»` are now valid as program delimiters. `<<` and `>>` are still valid
- entering the sign after the base (ex: 0x-1e2) is allowed
- rpn is delivered as flatpak and snap packages to be compatible with a maximum of Linux distribs. rpm and deb are no longer generated
Compatibility is broken on these points
- `<< <<` input doesn't lead to `««»»` but to `«<< »`, preventing to eval the real program content
- `1 2+` not allowed anymore, keep `1 2 +`, this corrects bad behaviors like `3b114` pushing `3b11` and `4`
- complexes are written in the form `(1,2)` instead of `(1, 2)` (space is removed)
- removed useless `unti`, `repea`, `whil` (prev.existing for HP28S compatibility)
- removed `sqr` function, please use `sq` instead (prev.existing for HP28S compatibility)
- the binary prefix is always 0b on display, but still can be 0b, 0B, 2b or 2B at input
- the hex prefix is always 0x on display, but still can be 0x, 0X or 16B at input
- `mant` and `xpon` now give binary (and not decimal) significand and exponent, as it is the norm in standard libs (libC, standard C++, mpfr, gmp)
- `dupn`, `roll`, `rolld` are not leaving anymore their argument in front of the stack in case of error
- `sto+` `sto-` `sto*` `sto/` don't accept anymore the syntax `'varname' value stoX`, but only `value 'varname' stoX`, ex: `3 'a' sto*`
- incomplete entry `(1,` is not available anymore
- signed zero is the sign of zero is subject to change compared to previous version, for example `-3 sqrt` now equals `(0.000000,1.732051)` instead of `(-0.000000,1.732051)`
- removed CtrlC for interrupting a program (considered useless)
Debug
- `sub` now only accepts boundaries between 1 and the string length
- `sto/` behavior: sto/ now correctly stores variable / constant and not constant / variable
- `cosh` now returns the hyp cosinus instead of the hyp sinus (!)

View file

@ -1,58 +1,29 @@
# **rpn v2.3.2** - generation
# Generation
For now rpn is proposed only for **GNU/Linux**
rpn is proposed for **GNU/Linux**.
It can be generated following the steps below
It can be generated following the steps below.
## version identification
rpn is dynamically linked against GNU MP and GNU MPFR and integrates [linenoise-ng](https://github.com/louisrubet/linenoise-ng.git) and [mpreal](http://www.holoborodko.com/pavel/mpfr/) code as git submodules.
rpn is dynamically linked against GNU MP and GNU MPFR
## Generate and install under Ubuntu 20.04 LTS
and embeds the source code of linenoise-ng as a submodule
It is necessary to get MPFR to generate rpn
## install GNU MPFR headers
- download **GNU MPFR** from http://www.mpfr.org
- install it with usual autotools commands `./configure && make && make install`
## generate rpn
- clone [rpn project](https://github.com/louisrubet/rpn/) or download a zipped version from [the release directory](https://github.com/louisrubet/rpn/releases)
```
# git clone https://github.com/louisrubet/rpn.git
```shell
sudo apt install git cmake g++ libmpfr6 libmpfr-dev
git clone https://github.com/louisrubet/rpn/
mkdir -p rpn/build && cd rpn/build
cmake ..
make -j
sudo make install
```
- make
CMake must be installed on the generation machine
## Generate and install under Fedora 35
```
# cd rpn/
# mkdir build
# cd build && cmake .. && make
```
- install
```
# cd rpn/build
# sudo make install
```
- packages
To build RPM package you should install CMake 2.6.0 or higher
```
# cd rpn/build
# sudo make package
[100%] Built target rpn
Run CPack packaging tool...
CPack: Create package using DEB
(...)
CPack: Create package using RPM
(...)
CPack: Create package using TGZ
(...)
```shell
sudo dnf install git cmake g++ mpfrf mpfr-devel
git clone https://github.com/louisrubet/rpn/
mkdir -p rpn/build && cd rpn/build
cmake ..
make -j
sudo make install
```

View file

@ -17,7 +17,7 @@ A help command is provided by rpn:
```
rpn> help
rpn v2.3.2, (c) 2017 <louis@rubet.fr>, GNU LGPL v3
rpn v2.4.0, (c) 2022 <louis@rubet.fr>, GNU LGPL v3
Reverse Polish Notation language
@ -47,6 +47,7 @@ rpn> 2 sqrt
```
### **programs** and **variables**
```
rpn> << rot * swap 2 / neg dup sq rot - sqrt >> 'quadratic_solution' sto
rpn> 1 2 -3 quadratic_solution
@ -77,7 +78,7 @@ rpn>
### object types
The following objects are managed: **floating numbers**, **complexes**, **symbols**, **strings**, **programs**, plus language **keywords** (commands and flow controls)
The following objects are managed: **floating numbers**, **complexes**, **symbols**, **strings**, **programs**, plus language **keywords** (commands and flow controls).
```
5> 12.3456
4> (1,-2.33)
@ -89,25 +90,22 @@ rpn>
### structured programming
Provided loop keywords **for|start..next|step**, **do..until**, **while..repeat** and control keywords **if..then..[else]..end**, **ift**, **ifte** allow you to program powerfull algorithms
Provided loop keywords **for|start..next|step**, **do..until**, **while..repeat** and control keywords **if..then..[else]..end**, **ift**, **ifte** allow you to program powerfull algorithms.
### command line
**rpn** is a cli interface with an **interactive editor** with autocompletion provided by **linenoise-ng**, see https://github.com/arangodb/linenoise-ng
**rpn** is a cli interface with an **interactive editor** with autocompletion provided by [linenoise-ng](https://github.com/arangodb/linenoise-ng).
Autocompletion works like those in Linux shells, with keys \<tab\>, Ctrl-R \<search pattern\> etc.
## entry
**reals** can be entered in decimal, binary, hexadecimal or arbitrary base from 2 to 62
- **reals** can be entered in decimal, binary, hexadecimal or arbitrary base from 2 to 62.
- Binaries (base 2) are entered as `0b<number>` or `0B<number>`.
- Hexadecimals (base 16) are entered as `0x<number>` or `0X<number>`.
- Arbitrary base numbers are entered as `<base>b<number>`.
- Representation can be individualy changed with keywords `dec`, `bin`, `hex` and `<n> base`.
binaries (base 2) are entered as `0b<number>` or `0B<number>`
hexadecimals (base 16) are entered as `0x<number>` or `0X<number>`
arbitrary base numbers are entered as `<base>b<number>`
representation can be individualy changed with keywords `dec`, `bin`, `hex` and `<n> base`
ex:
```
@ -258,9 +256,9 @@ rpn> 7b1252 dec
|`next`| used with start and for
|`step`| used with start and for
|`do`| `do (instructions) until (condition) end`
|`until` `unti` | used with do
|`while` `whil`| `while (test-instruction) repeat (loop-instructions) end`
|`repeat` `repea`| used with while
|`until` | used with do
|`while` | `while (test-instruction) repeat (loop-instructions) end`
|`repeat` | used with while
### store

View file

@ -1,23 +0,0 @@
# Development methods
## Versioning
The software version number conforms to [SemVer semantic 2.0.0](https://semver.org/), aka `v<MAJOR>.<MINOR>.<PATCH>`
Suffixes `alpha` or `beta` are not used
## Workflow
This project conforms to the usual **gitflow** workflow as seen in ![gitflow image](https://i.stack.imgur.com/QxVmJ.png)
Report to Vincent Driessen page [a-successful-git-branching-model](http://nvie.com/posts/a-successful-git-branching-model/) for a detailed explanation of this workflow
Branches are named as follows:
|branch name| description |
|-|-|
|`master`|usual main git branch, always holds the last software version and its tag plus documents not changing the sw version |
|`hotfix-vx.y.z`|hotfixes branches|
|`release-vx.y.0`|releases branches, patch number should always be 0 here|
|`develop`|dev branch|
|`any name`|feature branches|

123
README.md
View file

@ -1,67 +1,118 @@
# **rpn** - **R**everse **P**olish **N**otation language [![License: LGPLv3](https://www.gnu.org/graphics/lgplv3-88x31.png)](https://www.gnu.org/licenses/lgpl-3.0.en.html)
# **rpn** - **R**everse **P**olish **N**otation CLI calculator [![License: LGPLv3](https://www.gnu.org/graphics/lgplv3-88x31.png)](https://www.gnu.org/licenses/lgpl-3.0.en.html)
### a math functional language using reverse polish notation
A math functional language using reverse polish notation.
```
### A math functional language using reverse polish notation
```rpn
rpn> 1 2 + 2 sqrt
2> 3
1> 1.4142135623730950488
```
### arbitrary precision provided by GNU MPFR
### Manipulating reals, complexes, strings, variables on a stack
```rpn
rpn> 1 2 + 2
2> 3
1> 2
rpn> r->c sq conj (1,1) /
(-3.5,-8.5)
```
```rpn
rpn> "sqrt of 2 is " 2 sqrt ->str +
"sqrt of 2 is 1.4142135623730950488016887242096980786"
```
```rpn
rpn> << -> x << x 3 ^ 2 x * - 3 + >> >> 'f' sto
rpn> 2 f
7
rpn> (1,2) f
(-10,-6)
```
### Arbitrary precision provided by GNU MPFR
```rpn
rpn> 256 prec
rpn> pi
3.1415926535897932384626433832795028841971693993751058209749445923078164062862
rpn>
```
### variables, programs
```
rpn> << rot * swap 2 / chs dup sq rot - sqrt >> 'quad' sto
rpn> << -> x y << x y + ln >> >> 'P' sto
### Variables, strings, structured programming
```rpn
rpn> « rot * swap 2 / chs dup sq rot - sqrt » 'quad' sto
rpn> 0 1 10000 for i i sq + next
333383335000
rpn> a 1 > if then a sq 'calc' eval else 'stop' eval end
```
### and a bunch of functions
```
### Available functions
```rpn
rpn>
Display all 150 possibilities? (y or n)
nop pow fp >= dupn next sto* exp
help sqrt min < pick step sto/ expm
h sq max <= depth ift sneg log10
? sqr re != roll ifte sinv alog10
quit abs im == rolld do eval exp10
q dec conj and over until -> log2
exit hex arg or ->str unti pi alog2
test bin c->r xor str-> while sin exp2
version base r->c not chr whil asin sinh
uname sign p->r same num repeat cos asinh
history % r->p swap size repea acos cosh
+ %CH std drop pos sto tan acosh
- mod fix drop2 sub rcl atan tanh
chs fact sci dropn if purge d->r atanh
neg mant prec del then vars r->d time
* xpon round erase else clusr e date
/ floor default rot end edit ln ticks
inv ceil type dup start sto+ log
^ ip > dup2 for sto- lnp1
Display all 146 possibilities? (y or n)
nop pow conj < pick step eval exp10
help sqrt arg <= depth ift -> log2
h sq c->r != roll ifte pi alog2
? abs r->c == rolld do sin exp2
quit sign p->r and over until asin sinh
q % r->p or ->str while cos asinh
exit %CH std xor str-> repeat acos cosh
test mod fix not chr sto tan acosh
version fact sci same num rcl atan tanh
uname mant prec swap size purge d->r atanh
history xpon round drop pos vars r->d time
+ floor default drop2 sub clusr e date
- ceil type dropn if edit ln ticks
* ip hex del then sto+ log
/ fp dec erase else sto- lnp1
inv min bin rot end sto* exp
chs max base dup start sto/ expm
neg re > dup2 for sneg log10
^ im >= dupn next sinv alog10
```
## Download
deb, rpm and tgz files can be found [there](liv/)
Available as source code and flatpak under [flathub](https://flathub.org/apps/category/Science) (_coming soon_).
## Manual
A reference manual is provided [here](MANUAL.md)
## Methods
Development methods are set at [this page](METHODS.md)
## Generation
Generation instructions can be found [here](GENERATION.md)
rpn is written in C++ and is dynamically linked against GNU MP and GNU MPFR.
It integrates [linenoise-ng](https://github.com/louisrubet/linenoise-ng.git) and [mpreal](http://www.holoborodko.com/pavel/mpfr/) code as git submodules.
It can be generated following the steps below:
## Generate and install under Ubuntu 20.04 LTS
```shell
sudo apt install git cmake g++ libmpfr6 libmpfr-dev
git clone https://github.com/louisrubet/rpn/
mkdir -p rpn/build && cd rpn/build
cmake ..
make -j
sudo make install
```
## Generate and install under Fedora 35
```shell
sudo dnf install git cmake g++ mpfrf mpfr-devel
git clone https://github.com/louisrubet/rpn/
mkdir -p rpn/build && cd rpn/build
cmake ..
make -j
sudo make install
```
## Contact, contribution, bug report

View file

@ -1,10 +0,0 @@
.TH RPN 1
.SH NAME
rpn \- Reverse Polish Notation calculator
.SH SYNOPSIS
.B rpn
.IR commands ...
.SH DESCRIPTION
.B rpn is a full-featured math-oriented structured language inspired by Hewlett-Packard Reverse Polish Lisp
Please visit https://github.com/louisrubet/rpn for source code, a manual and generation instructions

@ -1 +1 @@
Subproject commit 6a37ee0e9f117bb9950159545ecdbdbba41799bf
Subproject commit e20977cddd1a5bec3672ecd1a388a5f9ffdefa9a

View file

@ -9,27 +9,22 @@ using std::cout, std::string, std::pair;
#include "program.h"
#include "version.h"
// description
#define ATTR_BOLD "\33[1m"
#define ATTR_OFF "\33[0m"
#define XSTR(a) STR(a)
#define STR(a) #a
static const char _description[] = ATTR_BOLD
"R" ATTR_OFF "everse " ATTR_BOLD "P" ATTR_OFF "olish " ATTR_BOLD "N" ATTR_OFF "otation language\n\nusing " ATTR_BOLD
"GMP" ATTR_OFF " v" XSTR(__GNU_MP_VERSION) "." XSTR(__GNU_MP_VERSION_MINOR) "." XSTR(
__GNU_MP_VERSION_PATCHLEVEL) " under GNU LGPL\n" ATTR_BOLD "MPFR" ATTR_OFF " v" MPFR_VERSION_STRING
" under GNU LGPL\nand " ATTR_BOLD "linenoise-ng" ATTR_OFF " v" LINENOISE_VERSION
" under BSD\n";
static const char _syntax[] = ATTR_BOLD "Syntax" ATTR_OFF ": rpn [command]\nwith optional command = list of commands";
#define MPFR_ROUND \
{"nearest (even)", MPFR_RNDN}, {"toward zero", MPFR_RNDZ}, {"toward +inf", MPFR_RNDU}, {"toward -inf", MPFR_RNDD}, \
{"away from zero", MPFR_RNDA}, {"faithful rounding", MPFR_RNDF}, { \
"nearest (away from zero)", MPFR_RNDNA \
}
static const char _description[] =
ATTR_BOLD "R" ATTR_OFF "everse " ATTR_BOLD "P" ATTR_OFF "olish " ATTR_BOLD "N" ATTR_OFF "otation CLI calculator";
static const char _syntax[] = ATTR_BOLD "Syntax" ATTR_OFF ": rpn [command]\nwith optional command = list of commands";
static const char _uname[] = ATTR_BOLD "rpn v" RPN_VERSION ", (c) 2022 <louis@rubet.fr>" ATTR_OFF;
/// @brief nop keyword implementation
///
void program::RpnNop() {
@ -45,7 +40,7 @@ void program::RpnQuit() { ERROR_CONTEXT(kGoodbye); }
///
void program::RpnHelp() {
// software name
cout << endl << ATTR_BOLD << RPN_UNAME << ATTR_OFF << endl;
cout << endl << _uname << endl;
// _description
cout << _description << endl << endl;
@ -90,7 +85,7 @@ void program::RpnHelp() {
cout << "Current rounding mode is '" << rn.first << '\'' << endl;
break;
}
cout << endl << endl;
cout << endl;
}
/// @brief whether a printed precision is in the precision min/max
@ -161,7 +156,7 @@ void program::RpnVersion() { stack_.push_front(new String(RPN_VERSION)); }
/// @brief _uname keyword implementation
///
void program::RpnUname() { stack_.push_front(new String(RPN_UNAME)); }
void program::RpnUname() { stack_.push_front(new String(_uname)); }
/// @brief history keyword implementation
///

View file

@ -4,6 +4,5 @@
#define SRC_VERSION_H_
#define RPN_VERSION GIT_VERSION // set by cmake from git tag
#define RPN_UNAME "rpn v" RPN_VERSION ", (c) 2017 <louis@rubet.fr>, GNU LGPL v3"
#endif // SRC_VERSION_H_