Thread: Math help?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    91

    Math help?

    I have the following code:

    Code:
    #include <msp430.h>#include "stdlib.h"
    #include "stdio.h"
    
    
        const char frq[8], br[8];
        long f, b;
        char *frqPtr, *brPtr;
        int d;
        float interim;
    
    
    void main()
    {
        strcpy(frq, "16000000");
        strcpy(br, "115200");
        f = atol(frq);
        b = atol(br);
        interim = f/b/16;
        d = (int)((interim - (int)interim) * 16);
    }
    After I run I get the following from the debugger:
    interim float 8.0 0x002018
    d int 0 0x00201C
    f long 16000000 0x002014
    b long 115200 0x002010

    Can someone tell me how to get interim = 8.68055555556 and d = 10?

    Problem solved: change f, b to float and cast
    Last edited by ridgerunnersjw; 10-31-2020 at 04:14 PM. Reason: Solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <math.h> help
    By evildotaing in forum C++ Programming
    Replies: 14
    Last Post: 02-02-2012, 05:38 PM
  2. Math
    By knightjp in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 05:36 PM
  3. math.h
    By derrickn in forum C Programming
    Replies: 3
    Last Post: 08-04-2005, 08:43 PM
  4. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 03:14 AM
  5. Math Help
    By CAP in forum C Programming
    Replies: 2
    Last Post: 08-19-2002, 12:03 AM

Tags for this Thread