#define N '\0'
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int getop(char []);
void push(double);
double pop(void);

int main()
{
  char s[100];
  int w;
  double op;

  while((w = getop(s)) != EOF && w < 100) {
    switch (w) {
    case '0':
      push(atof(s));
      break;
      
    case '+':
      push(pop() + pop());
      break;
      
    case '*':
      push(pop() * pop());
      break;
      
    case '-':
      op = pop();
      push(pop() - op);
      break;
      
    case '\n':
      printf("%.8g\n", pop());
      break;
      
    default:
      printf("error: unknown command %s\n", s);
      break;
    }
  }
  return 0;
}

double V[100];
int sp = 0;

void push(double f)
{
  if (sp < 100)
    V[sp++] = f;
  else
    printf("error: stack full, can't push %g\n", f);
}

double pop(void)
{
  if (sp > 0)
    return V[--sp];
  else {
    printf("error: stack empty\n");
    return 0.0;
  }
}

#include <ctype.h>

int getch(void);
void ungetch(int);

int getop(char argv[])
{
  int i,x;

  while ((argv[0]= x = getch()) == ' ' || x == '\t')
    
  argv[1] = N;
  if (!isdigit(x) && x != '.')
    return x;
  
  i = 0;
  if (isdigit(x))
    while (isdigit(argv[++i] = x = getch()))
      
  if (x == '.')
    while (isdigit(argv[++i] = x = getch()))
      
  argv[i] = N;
  if (x != EOF)
    ungetch(x);
  
  return '0';
}

char buf[100];
int bp = 0;

int getch(void)
{
  return (bp > 0) ? buf[--bp] : getchar();
}

void ungetch(int x)
{
  if (bp >= 100)
    printf("ungetch: too many characters\n");
  else
    buf[bp++] = x;
}

