Quick question. I've been looking desperately for a way calculate logarithm in a DOS batch data.Please help kindly.
Asked
Active
Viewed 919 times
1
-
cmd can't calculate with decimal numbers, eg. 3.1415692 :) – Endoro Apr 03 '13 at 22:16
3 Answers
3
the best way is making executable logarithm file and use it in your batch file, msdos have not any log function.. you can use some source code like this: http://en.literateprograms.org/Logarithm_Function_(Python)

Mehdi Yeganeh
- 2,019
- 2
- 24
- 42
-
+1: I agree: the logarithm computation could be done in Python, Perl, Awk or some other scripting language that returns the result on standard output. For example, if you have `bc` available (e.g. from Cygwin), you could use `echo l(2) | bc -l` to return log(2). – Simon Apr 03 '13 at 22:28
1
You may use this very simple Batch-JScript hybrid file:
@if (@CodeSection == @Batch) @then
@echo off
rem JSExpr.bat: Evaluate a JScript (aritmethic) expression
rem Antonio Perez Ayala
Cscript //nologo //E:JScript "%~F0" %1
goto :EOF
End of Batch section
@end
// JScript section
WScript.Echo(eval(WScript.Arguments.Unnamed.Item(0)));
For example:
C:>jsexpr Math.log(10)
2.30258509299405
As a matter of fact, you may evaluate any valid JScript arithmetic expression with previous program. For example:
C:>jsexpr Math.E
2.71828182845905
Search for "jscript reference" (math object), for example: http://msdn.microsoft.com/en-us/library/ie/b272f386(v=vs.94).aspx
Antonio

Aacini
- 65,180
- 12
- 72
- 108