Post Reply 
RPN-duino
10-24-2015, 10:45 AM (This post was last modified: 10-24-2015 11:07 AM by Chasfield.)
Post: #13
RE: RPN-duino
I have implemented the input and display of numbers in standard form on the RPN-DUINO calculator. The problem was that the the 1602 LCD print method only renders plain floating point numbers without exponents, displaying zero if the normal range is exceeded. Following the approach of another coder, I came up with this display formatting procedure that abstracts what is displayed from what is stored. Basically, I throw rocks at the stored "float" variable until it gives up its significand and exponent values, which can then be printed out on the LCD.

I sure ain't pretty but it does the job.

Code:

void lcd_format(float your_reg, int lcd_line){
   float your_significand = 0;
   int your_exp = 0;
   int d_places = 0;
   lcd.setCursor(0, lcd_line); 
   lcd.print("                    ");   
   lcd.setCursor(0, lcd_line); 
   your_exp = trunc(log10(abs(your_reg)));
   if ((abs(your_reg) >10000000) || (abs(your_reg) < 0.001) && (your_reg !=0)){  [i]// range of numbers requiring standard form[/i]
       your_significand =  your_reg/pow_ten(10, your_exp - 1); // reduce the stored float value to a printable significand
       if (abs(your_reg) < 1.0) { // adjust for negative exponents to give something to left of DP
           your_exp = your_exp -1;
           your_significand = your_significand * 10;}
        lcd.print(your_significand, 7);
        lcd.setCursor(11, lcd_line); 
        lcd.print ("E");        
        lcd.print(your_exp);}
    else  // if variable doesn't require display in standard form, suppress fictional significant figures [/i]
        {if (your_reg >= 1)  
                 d_places =  7 - your_exp;
          else 
                 d_places = 7;
         lcd.print(your_reg, d_places);}

Numbers keyed in by users in standard form are scaled by iterative multiplication/division with respect to their exponent. That makes them not directly displayable, but feeding them through the above mangler sorts that out.

I wrote a function "pow_ten", also used above, to do the iterative mult/div. I started out by using the built in math library pow() function but it was squandering precision.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RPN-duino - Chasfield - 10-16-2015, 03:55 PM
RE: RPN-duino - eried - 10-16-2015, 07:03 PM
RE: RPN-duino - David Hayden - 10-16-2015, 07:22 PM
RE: RPN-duino - Chasfield - 10-16-2015, 07:23 PM
RE: RPN-duino - Dwight Sturrock - 10-16-2015, 11:40 PM
RE: RPN-duino - eried - 10-16-2015, 08:50 PM
RE: RPN-duino - rprosperi - 10-16-2015, 09:23 PM
RE: RPN-duino - Chasfield - 10-17-2015, 04:38 AM
RE: RPN-duino - Thomas Klemm - 10-17-2015, 07:48 AM
RE: RPN-duino - rprosperi - 10-17-2015, 12:56 PM
RE: RPN-duino - Dwight Sturrock - 10-17-2015, 04:41 PM
RE: RPN-duino - Dave Frederickson - 10-17-2015, 05:02 PM
RE: RPN-duino - Vtile - 11-14-2015, 08:25 PM
RE: RPN-duino - walter b - 11-14-2015, 09:11 PM
RE: RPN-duino - Chasfield - 10-24-2015 10:45 AM
RE: RPN-duino - ggauny@live.fr - 10-29-2015, 08:26 AM
RE: RPN-duino - vido - 09-18-2016, 06:50 PM
RE: RPN-duino - Chasfield - 11-14-2015, 05:27 PM
RE: RPN-duino - Thomas Klemm - 11-14-2015, 05:48 PM
RE: RPN-duino - Chasfield - 11-15-2015, 10:28 AM
RE: RPN-duino - compsystems - 11-17-2015, 07:51 PM
RE: RPN-duino - Chasfield - 11-18-2015, 05:14 PM
RE: RPN-duino - Chasfield - 11-18-2015, 07:25 PM
RE: RPN-duino - Chasfield - 11-22-2015, 10:21 AM
RE: RPN-duino - Chasfield - 02-13-2016, 12:28 PM
RE: RPN-duino - Chasfield - 08-24-2016, 01:23 PM
RE: RPN-duino - Chasfield - 09-17-2016, 02:49 PM
RE: RPN-duino - larthurl - 04-06-2018, 02:29 PM
RE: RPN-duino - Luigi Vampa - 09-17-2016, 03:33 PM
RE: RPN-duino - Nigel (UK) - 09-17-2016, 06:57 PM
RE: RPN-duino - Chasfield - 09-18-2016, 01:52 PM
RE: RPN-duino - Nigel (UK) - 09-19-2016, 08:48 AM
RE: RPN-duino - Maximilian Hohmann - 09-19-2016, 09:44 AM
RE: RPN-duino - Chasfield - 09-19-2016, 02:35 PM
RE: RPN-duino - Luigi Vampa - 09-19-2016, 04:05 PM
RE: RPN-duino - jch - 09-19-2016, 07:08 PM
RE: RPN-duino - Chasfield - 09-28-2016, 03:24 PM
RE: RPN-duino - Chasfield - 09-28-2016, 05:01 PM
RE: RPN-duino - Luigi Vampa - 09-28-2016, 07:23 PM
RE: RPN-duino - Chasfield - 09-29-2016, 06:51 AM
RE: RPN-duino - Chasfield - 09-30-2016, 06:50 PM
RE: RPN-duino - Chasfield - 10-01-2016, 01:18 PM
RE: RPN-duino - Luigi Vampa - 10-01-2016, 03:20 PM
RE: RPN-duino - Chasfield - 10-01-2016, 03:31 PM
RE: RPN-duino - Chasfield - 10-01-2016, 05:39 PM
RE: RPN-duino - Luigi Vampa - 10-01-2016, 06:38 PM
RE: RPN-duino - Chasfield - 10-01-2016, 07:00 PM
RE: RPN-duino - Luigi Vampa - 10-02-2016, 09:14 AM
RE: RPN-duino - Luigi Vampa - 10-02-2016, 12:43 PM
RE: RPN-duino - Chasfield - 10-02-2016, 01:54 PM
RE: RPN-duino - Chasfield - 10-16-2016, 03:41 PM
RE: RPN-duino - Luigi Vampa - 10-16-2016, 07:49 PM
RE: RPN-duino - larthurl - 04-06-2018, 02:38 PM
RE: RPN-duino - Chasfield - 10-17-2016, 05:31 AM
RE: RPN-duino - Chasfield - 10-27-2016, 02:13 PM
RE: RPN-duino - Luigi Vampa - 10-27-2016, 08:27 PM
RE: RPN-duino - Chasfield - 10-28-2016, 01:20 PM
RE: RPN-duino - Chasfield - 03-25-2017, 03:02 PM
RE: RPN-duino - Luigi Vampa - 03-25-2017, 09:52 PM
RE: RPN-duino - Chasfield - 03-26-2017, 08:32 AM
RE: RPN-duino - Chasfield - 03-27-2017, 03:19 PM
RE: RPN-duino - Maximilian Hohmann - 03-27-2017, 03:58 PM
RE: RPN-duino - BobVA - 03-27-2017, 05:00 PM
RE: RPN-duino - Chasfield - 03-27-2017, 04:42 PM
RE: RPN-duino - Chasfield - 07-19-2017, 04:51 PM
RE: RPN-duino - Luigi Vampa - 07-19-2017, 05:26 PM
RE: RPN-duino - EugeneNine - 07-19-2017, 06:12 PM
RE: RPN-duino - Chasfield - 07-24-2017, 01:50 PM
RE: RPN-duino - Dan - 07-27-2017, 03:44 AM
RE: RPN-duino - larthurl - 11-28-2017, 09:11 PM
RE: RPN-duino - Luigi Vampa - 11-28-2017, 09:40 PM
RE: RPN-duino - Chasfield - 04-05-2018, 04:41 PM
RE: RPN-duino - Luigi Vampa - 04-05-2018, 04:44 PM
RE: RPN-duino - Luigi Vampa - 04-06-2018, 02:41 PM
RE: RPN-duino - Chasfield - 04-06-2018, 06:14 PM
RE: RPN-duino - Chasfield - 04-08-2018, 10:34 AM



User(s) browsing this thread: 1 Guest(s)