LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   I need a calculator (https://www.linuxquestions.org/questions/programming-9/i-need-a-calculator-289461/)

Starch 02-12-2005 06:28 PM

I need a calculator
 
Is there a good calculator on linux. I need one that I can enter a formula and execute it and get back a result in hex, binary, decimal. I like this calculator but its for windows. compiling a C program is great but it takes too long for something like 1+1 because it needs to be compiled.

Thanks in advance!

ilikejam 02-12-2005 06:58 PM

Hi.

kcalc can do what you're looking for.

Dave

Starch 02-12-2005 07:09 PM

Nice calculator, is there anyway to show everything I typed? instead of just the answer or what I am currently typing in.

Thanks in advance!

ilikejam 02-12-2005 07:25 PM

Not really.

There is a command line utility called 'dc' which might suit you...
For example, to do 2+5, and have the result in base 16 (Hex), you would do:
dc <return>
16 <return>
o <return> (that's a letter o, not a zero)
2 <return>
5 <return>
+ <return>
p <return>

The only problem is that dc can only do simple math (+-*/^ and such). It does, though have the advantage that you can echo a stream of commands to it, and get the result that way, so it can be scripted.

'bc' is more powerful than 'dc', and can apparently do cos and sin etc, but I haven't had any reason to use it over 'dc' yet, so I don't know its syntax. Have a look at 'man bc' if you need a more powerful calculator, and don't mind the command line.

xcalc, and kcalc are the only GUI calculators I have come accross on Linux.

Dave

perfect_circle 02-14-2005 12:38 PM

Quote:

Originally posted by Starch
Nice calculator, is there anyway to show everything I typed? instead of just the answer or what I am currently typing in.

Thanks in advance!

You may try mathomatic:
http://www.linuxpackages.net/search_...matic&ver=10.0

AnanthaP 02-14-2005 06:06 PM

First off.
javascript:eval() in the address bar will do the AnalogX example in decimal.

On the same note, you should be able to eval any expression, then convert to all common bases decimal using javascript functions (beware of base 10 numbers with high order zeros being taken as octal and throwing out errors) and then write a reasonable html based (it's free) look alike.

I wrote this function to work in a "NumConv" type utility modeled after my old CASIO PV organiser.
*******
function makeString(MyNum, Radix) {
MyDiv=MyNum ;
MyString="" ;
MyChar="" ;
MyRem = 0 ;
while (MyDiv != 0) {
MyRem=MyDiv%Radix ;
if (MyRem < 10) MyChar=MyRem.toString() ;
if (MyRem == 15) MyChar = "F" ;
if (MyRem == 14) MyChar = "E" ;
if (MyRem == 13) MyChar = "D" ;
if (MyRem == 12) MyChar = "C" ;
if (MyRem == 11) MyChar = "B" ;
if (MyRem == 10) MyChar = "A" ;
MyString=MyChar+MyString ;
MyDiv=(MyDiv-MyRem) / Radix ;
}
// alert("In Make:" + MyNum.toString() + ":" + MyString) ;
return MyString ;
}
********
Tested for radix = 2, 8, 16 and thre calls will give you most common bases.

End


All times are GMT -5. The time now is 11:20 AM.