Giter Site home page Giter Site logo

vapier / pcalc Goto Github PK

View Code? Open in Web Editor NEW
114.0 5.0 19.0 183 KB

command line util for doing hex/dec/oct/bin math quickly

Home Page: https://vapier.github.io/pcalc/

License: GNU General Public License v2.0

Makefile 5.48% C 57.45% Yacc 18.74% Lex 17.93% Python 0.40%
programmer-tool c calculator

pcalc's Introduction

pcalc: The Programmer's calculator

Build Status

There was always a loophole when it came to a need to covert between hexadecimal / decimal / octal / binary.

Especially if it involved an operation like 0x1234 + 0x20. It took a lot of hard work, and mostly a good pocket calculator.

Features

  • Full math parser, parentheses, add, sub, mult, div, exponential
  • Automatic conversion between HEX DEC OCT BIN numbers
  • Mixing different bases in one expression
  • Definable variables
  • Math constants (E PI ...)
  • Built in math functions (sin/cos/sqrt ...)

Examples

Here are bunch of common examples.

See the SYNTAX.md file for the full syntax. You can also run pcalc for a local reference.

$ pcalc 0x300
        768                     0x300                   0y1100000000

# Note: Shell expansion on the '*' char requires the single quotes.
$ pcalc '0x300 + 3 * 3'
        777                     0x309                   0y1100001001

$ pcalc sqrt 2
        1.414213562373095       0x1                     0y1

# Note: The single quotes are to keep the shell happy with the () characters.
$ pcalc 'sqrt(2)'
        1.414213562373095       0x1                     0y1

$ pcalc 0x12 or 23
        23                      0x17                    0y10111

# To execute a script, use the `@` prefix on the filename.
$ pcalc @pcalc.001

Building & Installing

To compile the project, simply use make:

$ make

Note: Some platforms might not provide flex or -lfl. You will need to adjust the Makefile accordingly.

To install it, you can do:

$ sudo make install

Testing

To run the unittests, use:

$ make check

Note: Depending on the precision of floating point math in your system, some unittests might fail. It's OK to ignore those specific failures.

Feedback

Please use the GH issue tracker for any updates/ports/suggestions. Feedback always welcome!

https://github.com/vapier/pcalc/issues

License

This project is licensed under GPLv2 (or later). The full text can be found in the COPYING file.

pcalc's People

Contributors

vapier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pcalc's Issues

`./testsuite` does not support `--jobs` under OpenBSD

The generated testsuite file does not support an --jobs flag under OpenBSD. Consider the terminal session below as an example.

Simply setting TESTSUITEFLAGS = appears to resolve this issue.

Tested under OpenBSD 6.4 on an AMD64 based system.

cad@nessus:~/D/pcalc > gmake MAKE=gmake check test
cc -ggdb -Wall -DVERSION='"4"'  -c -o pcalc.o pcalc.c
cc -ggdb -Wall -DVERSION='"4"'  -c -o pcalcl.o pcalcl.c
pcalcl.c:1705:17: warning: unused function 'yyunput' [-Wunused-function]
    static void yyunput (int c, char * yy_bp )
                ^
pcalcl.c:1746:16: warning: function 'input' is not needed and will not be emitted
      [-Wunneeded-internal-declaration]
    static int input  (void)
               ^
2 warnings generated.
cc -ggdb -Wall -DVERSION='"4"'  -c -o funct.o funct.c
cc -ggdb -Wall -DVERSION='"4"'  -c -o math.o math.c
cc -ggdb -Wall -DVERSION='"4"'  -c -o symbol.o symbol.c
cc -ggdb -Wall -DVERSION='"4"'  -c -o help.o help.c
cc -ggdb -Wall -DVERSION='"4"'  -c -o store.o store.c
cc -ggdb -Wall -DVERSION='"4"'  -c -o print.o print.c
cc -ggdb -Wall -DVERSION='"4"'  -c -o str.o str.c
cc -ggdb -Wall -DVERSION='"4"'  -c -o convert.o convert.c
cc -ggdb -Wall  pcalc.o pcalcl.o funct.o math.o symbol.o help.o store.o print.o str.o con
ert.o  -lm -lfl -o pcalc
symbol.o: In function `install_sym':
/home/cad/Downloads/pcalc/symbol.c:171: warning: strcpy() is almost always misused, pleas
 use strlcpy()
store.o: In function `store':
/home/cad/Downloads/pcalc/store.c:93: warning: sprintf() is often misused, please use snp
intf()
gmake -C ptest check
gmake[1]: Entering directory '/home/cad/Downloads/pcalc/ptest'
./testsuite --jobs=`getconf _NPROCESSORS_ONLN || echo 1`
getconf: _NPROCESSORS_ONLN: unknown variable
testsuite: error: invalid variable name: --jobs
gmake[1]: *** [Makefile:39: check] Error 1
gmake[1]: Leaving directory '/home/cad/Downloads/pcalc/ptest'
gmake: *** [Makefile:39: check] Error 2
cad@nessus:~/D/pcalc > ./ptest/testsuite --help
Usage: ./ptest/testsuite [OPTION]... [VARIABLE=VALUE]... [TESTS]

Run all the tests, or the selected TESTS, and save a detailed log file.
Upon failure, create debugging scripts.

You should not change environment variables unless explicitly passed
as command line arguments.  Set `AUTOTEST_PATH' to select the executables
to exercise.  Each relative directory is expanded as build and source
directories relatively to the top level of this distribution.  E.g.,

  $ ./ptest/testsuite AUTOTEST_PATH=bin

possibly amounts into

  PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:$PATH

Operation modes:
  -h, --help     print the help message, then exit
  -V, --version  print version number, then exit
  -c, --clean    remove all the files this test suite might create and exit
  -l, --list     describes all the tests, or the selected TESTS

Execution tuning:
  -k, --keywords=KEYWORDS
                 select the tests matching all the comma separated KEYWORDS
                 accumulates
  -e, --errexit  abort as soon as a test fails; implies --debug
  -v, --verbose  force more detailed output
                 default for debugging scripts
  -d, --debug    inhibit clean up and debug script creation
                 default for debugging scripts
  -x, --trace    enable tests shell tracing

Report bugs to <https://github.com/vapier/pcalc/issues>.

pcalc install

I have problem in installing pcalc on my opensuse leap 42.2 machine.

Could you please give me hints ?

Regards,

MarcoC

test 12 failes on macppc

testsuite.log

As noted, test 12 fails under OpenBSD 6.4/macppc.

Further potentially useful information:

cad@montag:/u/p/p/p/p/ptest > sysctl hw
hw.machine=macppc
hw.model=7447A (Revision 0x105)
hw.ncpu=1
hw.byteorder=4321
hw.pagesize=4096
hw.disknames=wd0:c375357beab85361,cd0:
hw.diskcount=2
hw.sensors.maxtmp0.temp0=49.25 degC (Internal)
hw.sensors.maxtmp0.temp1=45.00 degC (External)
hw.cpuspeed=1499
hw.vendor=Apple Computer, Inc.
hw.product=PowerMac10,2
hw.physmem=1073741824
hw.usermem=1073729536
hw.ncpufound=1
hw.allowpowerdown=1
hw.ncpuonline=1
cad@montag:/u/p/p/p/p/ptest > uname -a
OpenBSD montag.int.cxd.guru 6.4 GENERIC#231 macppc

Test regression from 4 -> 5 on sparc

Hi, the unit tests which are passing on v4 are failing on v5 on sparc.

Relevant snippet:

## ---------------------- ##
## Detailed failed tests. ##
## ---------------------- ##

#                             -*- compilation -*-
1. pcalc.001.at:1: testing pcalc.001 ...
/pcalc.001.at:1: ${top_builddir:-$at_dir/..}/pcalc @${srcdir:-$at_dir}/pcalc.001 | \
	sed \
		-e 's:[	 ][	 ]*: :g' \
		-e 's: *$::'

--- -	2023-12-20 04:54:09.304649598 +0000
+++ /var/tmp/portage/sci-calculators/pcalc-5/work/pcalc-5/ptest/testsuite.dir/at-groups/1/stdout	2023-12-20 04:54:09.293040691 +0000
@@ -15,7 +15,7 @@
 LOG:
  2.302585092994046 0x2 0y10
  0.4342944819032518 0x0 0y0
- 1 0x1 0y1
+ 1 0x0 0y0
 Fahrenheit to celsius: 80F
  26.66666666666667 0x1a 0y11010
 
1. pcalc.001.at:1: 1. pcalc.001 (pcalc.001.at:1): FAILED (pcalc.001.at:1)


#                             -*- compilation -*-
1. pcalc.001.at:1: testing pcalc.001 ...
/pcalc.001.at:1: ${top_builddir:-$at_dir/..}/pcalc @${srcdir:-$at_dir}/pcalc.001 | \
	sed \
		-e 's:[	 ][	 ]*: :g' \
		-e 's: *$::'

--- -	2023-12-20 04:54:09.304649598 +0000
+++ /var/tmp/portage/sci-calculators/pcalc-5/work/pcalc-5/ptest/testsuite.dir/at-groups/1/stdout	2023-12-20 04:54:09.293040691 +0000
@@ -15,7 +15,7 @@
 LOG:
  2.302585092994046 0x2 0y10
  0.4342944819032518 0x0 0y0
- 1 0x1 0y1
+ 1 0x0 0y0
 Fahrenheit to celsius: 80F
  26.66666666666667 0x1a 0y11010
 
1. pcalc.001.at:1: 1. pcalc.001 (pcalc.001.at:1): FAILED (pcalc.001.at:1)

Downstream bug: https://bugs.gentoo.org/920351

Complete log: https://920351.bugs.gentoo.org/attachment.cgi?id=880026

If you need real hardware to test this on, I offer free shell access to the machine I reproduced this issue on. Thanks for taking a look!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.