markdown 一个用Go编写的简单,快速,直观的命令行计算器。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 一个用Go编写的简单,快速,直观的命令行计算器。相关的知识,希望对你有一定的参考价值。

calc
====

[GitHub](https://github.com/alfredxing/calc "A simple command-line calculator written in Go")

A simple, fast, and intuitive command-line calculator written in Go.

Install
-------

Install calc as you would any other Go program:
```bash
go get github.com/alfredxing/calc
```

Usage
-----

You can use `calc` in two ways: __shell__ mode and __command__.


### Shell mode

This is probably the mode you'll want to use. It's like the `python` shell or `irb`. The shell mode uses the `terminal` package provided by [`golang.org/x/crypto/ssh/terminal`](https://godoc.org/golang.org/x/crypto/ssh/terminal), which means it supports many of the shell features you know and love (like history, pasting, and the `exit` command).

```
> 1+1
2
> 3(5/(3-4))
-15
> 3pi^2
29.608813203268074
> @+1
30.608813203268074
> @@@*2
-30
> ln(-1)
NaN
```


### Command
You can also use calc to evaluate an expression with just a single command (i.e. without opening the shell). To do this, just use `calc [expression]`:
```bash
calc 1+1
```

    2

Supported functions, operators, and constants
---------------------------------------------

`calc` supports all the standard stuff, and I'm definitely adding more later (also feel free to fork and add your own!)


#### Operators
`+`, `-`, `*`, `/`, `^`, `%`


#### Functions
`sin`, `cos`, `tan`, `cot`, `sec`, `csc`, `asin`, `acos`, `atan`, `acot`, `asec`, `acsc`, `sqrt`, `log`, `lg`, `ln`, `abs`


#### Constants
`e`, `pi`, `π`


#### History

Previous results can be accessed with the `@` symbol. A single `@` returns the result of the last computation, while multiple `@` gets the n<sup>th</sup> last result, where n is the number of `@`s used (for example, `@@` returns the second-last result, `@@@@@` returns the fifth-last result).


Why not use ...?
----------------

- Google
  - Doesn't work without an internet connection
  - Slower
  - Doesn't show previous computations, so you end up with multiple tabs open at once.
- Spotlight (on OS X)
  - No history
  - Switching between Spotlight and other windows isn't too fun
- Python/IRB
  - Requires use of a separate math module for most functions and constants
  - A little bit slower to start up
- `bc`
  - Limited number of built-in functions; these have shortened (not too intuitive) names as well.

The alternatives above are all great, and have their own advantages over calc. I highly recommend looking into these if you don't like how calc works.

以上是关于markdown 一个用Go编写的简单,快速,直观的命令行计算器。的主要内容,如果未能解决你的问题,请参考以下文章

markdown 文档快速排版

3.6 万 Star!一个跨平台快速的轻量级 Web 服务器

[Cobra]Go语言的命令行编写工具的快速入门

用 Go 编写一个简单的 WebSocket 推送服务

用 Golang 快速实现 Paxos 分布式共识算法

用 Excel 生成和管理 Markdown 表格--转载