Shop OBEX P1 Docs P2 Docs Learn Events
Logarithm in Stamp — Parallax Forums

Logarithm in Stamp

SabaiSabai Posts: 27
edited 2010-01-14 20:58 in BASIC Stamp
I need to do this calulation in stamp Log (243/20) can not figur ut how to do that.

B

Comments

  • LeonLeon Posts: 7,620
    edited 2010-01-14 19:01
    Calculate the value and use it in your program?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
  • kf4ixmkf4ixm Posts: 529
    edited 2010-01-14 19:03
    Tracy Allen has a writeup/example of this on his site...

    http://www.emesys.com/BS2math3.htm#Logcalc

    hope this helps.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-01-14 19:20
    Log (243/20) is a constant =1.0846. Is there more to it than that?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • SabaiSabai Posts: 27
    edited 2010-01-14 19:42
    Tracy Allen said...
    Log (243/20) is a constant =1.0846. Is there more to it than that?

    Yepp there is more to it when that. All values are coming from Stamp so the correct thing is to write it like this Log(x/y).

    I looked one this page http://owlogic.com/BS2math3.htm#Logcalc but my problem is how to enter a value ie 12.15? I can add 1215 but not 12.15!

    B
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-14 19:47
    The Stamps only do integer arithmetic. They don't do floating point, so values like 12.15 can't exist in a Stamp. Arithmetic like this is always done using scaled fixed point arithmetic where 12.15 is represented as the integer 1215 and appropriate scaling is done during calculations. It is possible to attach an external floating point processor to a Stamp if you really have to do floating point including transcendental functions:
    www.parallax.com/StoreSearchResults/tabid/768/txtSearch/fpu/List/0/SortField/4/ProductID/401/Default.aspx
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-01-14 20:18
    In the Stamp integer math is is important to consider the scale factor. What is the range of x and y, or especially the range of the ratio x/y?

    Here is an example, PBASIC calculation of dewpoint from temperature and relative humidity: www.emesystems.com/programs/dewpoint.bsx.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • SabaiSabai Posts: 27
    edited 2010-01-14 20:42
    Iam going to use stamp to do calculation on Peukert's Equation (Peukert's Law) used for calculating lead batteri. I need to calculate the load on the battries and the time left on current load. All of that includes logarithms. But I can work without decimals exept when the result is shown on the LCD. Let's say I got a value of 4560 but the trus valu I need to show on the lcd is 4.56. I can take 4560 / 1000 = 4.56 but as you say stamp cannot handle that so how do I do that?

    B
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-14 20:51
    You can easily format an integer with an embedded decimal point like this:

    a = 4560
    SEROUT pin,Baud,[noparse][[/noparse]DEC a/1000,".",DEC3 a//1000] ' shows 4.560
    SEROUT pin,Baud,[noparse][[/noparse]DEC a/1000,".",DEC2 (a//1000)/10] ' shows 4.56
  • SabaiSabai Posts: 27
    edited 2010-01-14 20:55
    YEs its easy on a serial but I am using parallel lcd

    B
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-14 20:58
    The DIG operator allows you to extract individual digits from the decimal representation of an integer value. It's easy enough to do your own formatting inserting a decimal point as needed during output to the parallel LCD. It's easy on a serial LCD, but harder with a parallel LCD on a BS2 Stamp. The BS2p Stamps have built-in support for a parallel LCD including the same sort of formatting provided for SEROUT.
Sign In or Register to comment.