太好了,我现在可能不知道这意味着什么,但我会的。谢谢李,谢谢你的教训。
干杯
不客气。
关于对数的信息太多了,无法在论坛帖子中解释,但如果你有兴趣了解更多,可汗学院有一整节关于这个主题:
https://www.khanacademy.org/math/algebra/logarithms-tutorial
Here is another way to determine the number of digits:
(defun c:5dig ( / d n ) (while (and (setq n (getreal "\nEnter a 5-digit number: ")) (/= 5 (setq d (digits (setq n (fix n))))) ) (princ (strcat "\n" (itoa n) " has " (itoa d) " digits.")) ) n)(defun digits ( n ) (1+ (fix (/ (log n) (log 10)))))
Very nice Lee I knew there's a math solution to that besides using the usual operators.
Can you explain the function log in a way everyone else can understand it?
Cheers pBe
How long have you got?
To briefly explain, the AutoLISP log function returns the natural logarithm (usually written 'ln') of the supplied number, that is, the logarithm with base e (2.718...), or the inverse exponential function.
For logarithms in general we have:
log_a(b) = x=>a^x = bThat is, the logarithm base a of b results in a number such that a raised to that number will equal b.
In my function, I am calculating a value x such that:
n = 10^xUsing a logarithm of base 10 this can be easily calculated (since log_x(x) = 1):
n = 10^xlog_10(n) = log_10(10^x)log_10(n) = x(log_10(10))=> x = log_10(n)However, since we only have access to the natural logarithm function (log), we must proceed in the following way:
n = 10^xlog(n) = log(10^x)log(n) = x(log(10))=> x = log(n)/log(10)
Excellent, I may not know what that means now but in time I will. Thank you Lee, appreciate the lesson.
Cheers
You're very welcome.
There's far too much information on logarithms than could be explained in a forum post, but if you are interested in learning more, the Khan Academy have a whole section on the topic:
https://www.khanacademy.org/math/algebra/logarithms-tutorial
页:
1
[2]