Coder Social home page Coder Social logo

calc's Introduction

calc

최대한 정확한 계산기.

계산 방법

먼저 유리수(분수) 형태로 계산하기 시작합니다. 도중에 지수가 정수가 아닌 지수 연산 등 유리수로 정확하게 계산할 수 없는 식을 만나면, 유리수를 고정된 유효 숫자를 가진 소수로 변환하여 계산합니다.

지원하는 값의 형태

  • 과학적 표기법을 포함한 십진수(0, 1, -3, 4.2e1, 1E-9, 1.00e+12, ...)
  • 16진수(0x3, -0x0f, 0X7e, 0x8A, 0X300, ...)
  • 8진수(0o2, 0O17, ...)
  • 2진수(0b000, 0b1101, 0B001, ...)

지원하는 연산자

  • 사칙연산(+, -, *, /)
  • 지수(^)

지원하는 옵션

옵션은 계산할 식 앞에 공백을 사이에 두고 적습니다.

  • accurate: 항상 정확한 계산을 하며, 정확하지 않은 연산을 해야 할 때 오류를 냅니다.
  • precision (정수): 정확하지 않은 계산을 할 때, 소수의 정밀도를 지정합니다. 기본값은 20입니다.
  • print-decimal: 결과가 정확한 유리수로 나타나더라도 출력은 소수로 합니다. 정밀도 설정이 적용됩니다.

써 보기

yarn을 설치하고 다음 명령어를 실행하면 계산기를 써 볼 수 있습니다.

yarn
node app.js

입력과 출력 예시

> 1e9
1000000000
> 2^90
1237940039285380274899124224
> print-decimal 2^90
1.2379400392853802749e+27
> 2^0.5
2/1의 1/2제곱: 지수가 정수가 아니면 결과가 부정확할 수 있습니다.
1.4142135623730950488
> accurate 2^0.5
오류: 2/1의 1/2제곱: 지수가 정수가 아니면 결과가 부정확할 수 있습니다.
> precision 40 2^0.5
2/1의 1/2제곱: 지수가 정수가 아니면 결과가 부정확할 수 있습니다.
1.41421356237309504880168872420969807857
> 2^1e4
2/1의 10000/1제곱: 지수가 매우 크므로 부정확한 연산을 시도합니다.
1.9950631168807583849e+3010
> accurate 2^1e4
오류: 2/1의 10000/1제곱: 지수가 크면 정확한 연산에 시간이 오래 걸립니다.
> precision 100 2^1e4
2/1의 10000/1제곱: 지수가 매우 크므로 부정확한 연산을 시도합니다.
1.99506311688075838488374216268358508382349683188619245485200894985294388302219466319199616840361946e+3010

MIT License

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.