473,766 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating the log of a number

How do I calculate the log of a number? Don't tell me to use log in
cmath; I'm trying to learn complex math in C++. Got any tips/ideas on
how to do this? Thanks for the help!!!

Sep 16 '05 #1
21 8603
Go read a math book about how to calculate logarithms by hand. Than go
implement that in code.

Sep 16 '05 #2
"Protoman" writes:
How do I calculate the log of a number? Don't tell me to use log in
cmath; I'm trying to learn complex math in C++. Got any tips/ideas on
how to do this? Thanks for the help!!!


You could do it as the way shown here:

http://www.convertit.com/go/converti...es=150&Page=65
Sep 16 '05 #3
That's an ebook I have to purchase; I'd like a link to a place that's
free.

Sep 16 '05 #4
Protoman wrote:
That's an ebook I have to purchase; I'd like a link to a place that's
free.


The library?

john
Sep 16 '05 #5
I don't go there that often; it's so far away. I'd a like to another
site show how to do it, step by step, by hand, then I'll code it.

Sep 16 '05 #6
Protoman wrote:
I don't go there that often; it's so far away. I'd a like to another
site show how to do it, step by step, by hand, then I'll code it.


Fourtunately I have a vast library at my disposal.

log(z) = log|z| + i*phase(z)

phase(z) = atan2(imag(z), real(z))

There is actually some choice about how you calculate this sort of
thing, stuff to do with branch cuts etc. So the above isn't the only way
to do it. Nor should you read any mathematical expertise into my answer.
I'm just quoting from a book.

john
Sep 16 '05 #7

"Protoman" <Pr**********@g mail.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
How do I calculate the log of a number? Don't tell me to use log in
cmath; I'm trying to learn complex math in C++. Got any tips/ideas on
how to do this? Thanks for the help!!!


Normalize number into range 1<=x<2 by dividing/multiplying
by 2 repeatedly. Count how many times and call it exponent
(make it negative if normalization required dividing).

Next, repeatedly square the normalized number. Each time the
result >= 2 divide it by 2 and generate "1"; otherwise leave the
result as it is and generate "0". The generated stream of bits are
the fractional part of the exponent in base-2.

Then, the original number == 2^[exponent.fracti on] . Multiply
by a suitable constant to get bases other than 2.

- Risto -
Sep 16 '05 #8
Can you make that just a little clearer?

Sep 16 '05 #9
John Harrison wrote:
Protoman wrote:
I don't go there that often; it's so far away. I'd a like to another
site show how to do it, step by step, by hand, then I'll code it.


Fourtunately I have a vast library at my disposal.

log(z) = log|z| + i*phase(z)

phase(z) = atan2(imag(z), real(z))


Hmm, I misread your post, I thought you wanted to calculate the log of a
complex number.

Risto's answer sounded promising, and seemed pretty clear to me. Why not
try coding it and see how far you get.

john
Sep 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4492
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the difference. I want it to return the difference in years, months, days, hours, minutes and seconds (a complete summary). Keeping into account of course that these are 2 real dates, I dont want it to work with 30.475 as an average number of days in a...
5
8806
by: Ron Adam | last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone here for a great programming language. Below is my first Python program (not my first program) and I'd apreciate any feedback on how I might do things differently to make it either more consice, readable, or faster. ie... are there better ways to do it in Python? It won't break any records for calculating pi, that wasn't my goal, learning Python was. But it might...
4
12682
by: John | last post by:
hey all..... alright, I am frusterated to the point of throwing my machine out the window (this board went down, trying to find stuff on google, this has been a nightmare) so I hope you guys can help me with a solution. This is what I am trying to do: Pretty much, there are two dates in my database, a start date, and an end
5
11953
by: sugaray | last post by:
Hi, my problem with calculating the size of an array is when I pass an array as a parameter to a function which perform the calculation, the result never comes right, like below: int SizeOfArray(int a) { return (sizeof(a)/sizeof(a)); } main() { int a={1,2,3}; printf("%d\n",SizeOfArray(a));
3
12939
by: Ron Vecchi | last post by:
I need to calculate the age of a person based on a DateTime BirthDate I was thinking TimeSpan ts = DateTime.Now - BirthDate; //I can get the days but not years. // I could check each year from their year of birth, count the days in the year and compare with the days returned from timespan
3
5346
by: Miller | last post by:
Hi, Can someone tell me how to calculate MFLOPS for the following C# code (on a Pentium 4 2.0 Ghz)? for (i=0; i<n; i++) { for (j=0; j<n; j++) { for (k=0; k<n; k++)
0
2006
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master) and contains a list of dates. The data grid (Details portion) contains the details for a selected date (namely, a list of work codes and hours spent). I am trying to total the number of hours in the datagrid
10
3786
by: Lisa | last post by:
In translating the formula for calculating lottery odds for various conditions into a Visual Basic Program, I have apparently missed something in that I get errors in the part of the calculation where the number of ways of failure (pFal) is calculated Both errors happen in the code section x1 = Draw - MatchesReq x2 = Field - Selections For Counter = 1 To (Draw - MatchesReq - 1) x1 = x1 * (Draw - MatchesReq - Counter)
4
2091
by: =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= | last post by:
Say I have a class like, class Sample { public decimal first = 10; public decimal second = 20; } I have initialized it
1
3550
by: cmb3587 | last post by:
My code runs fine for the most part...the only time it fails is when I type in a negative to end the array. I don't want the negative number to be included in the array and I thought that is what the while loop in the getNums method does. However, it is including this negative number when calculating the avg and it is doing something weird to the median. When the array end itself because the max size has been reached everything works fine. ...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.