Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to get a logarithm of a number?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
genius12




PostPosted: Sun Nov 25, 2012 7:00 pm   Post subject: How to get a logarithm of a number?

What is it you are trying to achieve?

I am trying to get turing to find the logarithm of a number. I thought that there would probably be a function for logarithms in Turing but there isn't, or
atleast I didn't find one.


What is the problem you are having?
I can't find a function or a way to get the logarithm of a number.


Describe what you have tried to solve this problem
I have tried finding a function of method to find the logarithm of a number but was unsuccessful.


Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Sun Nov 25, 2012 8:04 pm   Post subject: Re: How to get a logarithm of a number?

Oh wow, Turing doesn't actually have log10, log(x, base) or any of that jazz.

Well, Turing doesn't have a very full arsenal in this reguard, nor will it ever be expanding. It does have the key function Math.ln(x) which will get you the natural logarithm.

Due to some math I can't quite remember, log(x, base) = ln(x) / ln(base). With that we can create our own functions.

Turing:

/**
 * Return the natural logarithm of x (to base e).
 */

% From the math module (Math.tu)
% function ln (r : real) : real

/**
 * Return the logarithm of x to the given base, calculated as log(x)/log(base)
 */

fcn log (x : real, base : real) : real
    result ln (x) / ln (base)
end log

/**
 * Return the base-10 logarithm of x.
 *
 * Notes: Normally this function would be more accurate than log(x, 10).
 */

fcn log10 (x : real) : real
    result log (x, 10)
end log10

put log (8, 2) % 3
put log (1 / 2, 2) % -1

put log10 (1) % 0
put log10 (10) % 1
put log10 (100) % 2
put log10 (1000) % 3

% put log(0,0) % ERROR
% put log10 (0) % ERROR
genius12




PostPosted: Sun Nov 25, 2012 8:42 pm   Post subject: Re: How to get a logarithm of a number?

Yup. Well didn't realise that Turing had a natural logarithm function. Thank you for pointing that out.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: