~aleteoryx/muditaos

muditaos/module-apps/application-calculator/data/CalculatorUtility.hpp -rw-r--r-- 1.1 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include <string>

namespace calc
{
    struct Result
    {
        std::string equation;
        std::string value;
        bool isError;
    };

    class Calculator
    {
        /// @param from: string which is going to be replaced
        /// @param to: string which is going to replace the old one
        /// @return: new string with replaced all occurrences of given string to the new one in whole input
        std::string replaceAllOccurrences(std::string input, const std::string &from, const std::string &to);
        std::string prepareEquationForParser(std::string input);
        std::string getValueThatFitsOnScreen(double result);
        long double getCoefficient(double result, uint32_t precision);
        std::string convertToNumberWithPositiveExponent(double result, uint32_t exponent);
        std::string convertToNumberWithNegativeExponent(double result, long long base);

      public:
        Result calculate(std::string source);
    };

} // namespace calc