Skip to content

Commit c7786e3

Browse files
committed
proper square root character for windows
1 parent bd75e15 commit c7786e3

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

inc/fraction.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ struct Fraction {
1414

1515
struct Error; // defined in utils.h
1616

17+
#ifdef _WIN32
18+
const char SQRT_CH[2] = {(char)251, (char)0};
19+
const int SQRT_LEN = 1;
20+
#else
21+
const char SQRT_CH[4] = "";
22+
const int SQRT_LEN = 3;
23+
#endif
24+
1725
void print_frac(Fraction const &m);
1826
Error load_frac(string s, Fraction &m);
1927
Fraction mul_frac(Fraction a, Fraction b);

src/evaluator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "evaluator.h"
22

33
set<char> banned_var_starts{'1','2','3','4','5','6','7','8','9','0','/','-'};
4-
set<char> frac_start{'-','1','2','3','4','5','6','7','8','9',""[0]};
4+
set<char> frac_start{'-','1','2','3','4','5','6','7','8','9',SQRT_CH[0]};
55

66
inline bool is_ptr(DataType t) {
77
return t == TYPE_MATRIX || t == TYPE_VECTOR;

src/fraction.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void print_frac(Fraction const &m) {
4545
cout << m.numerator;
4646
}
4747
if (m.sqrt != 1 && m.numerator != 0) {
48-
cout << "" << m.sqrt;
48+
cout << SQRT_CH << m.sqrt;
4949
}
5050
if (m.denominator != 1 && m.numerator != 0) {
5151
cout << "/" << m.denominator;
@@ -55,9 +55,9 @@ void print_frac(Fraction const &m) {
5555
Error load_frac(string s, Fraction &m) {
5656
if (s.find("/") == string::npos) {
5757
m.denominator = 1;
58-
if (s.find("") != string::npos) {
59-
m.sqrt = stoi(s.substr(s.find("") + 3));
60-
string num = s.substr(0, s.find(""));
58+
if (s.find(SQRT_CH) != string::npos) {
59+
m.sqrt = stoi(s.substr(s.find(SQRT_CH) + SQRT_LEN));
60+
string num = s.substr(0, s.find(SQRT_CH));
6161
if (num.length() == 0) m.numerator = 1;
6262
else if (num.length() == 1 && num[0] == '-') m.numerator = -1;
6363
else m.numerator = stoi(num);
@@ -67,9 +67,9 @@ Error load_frac(string s, Fraction &m) {
6767
}
6868
} else {
6969
string top = s.substr(0, s.find("/"));
70-
if (top.find("") != string::npos) {
71-
m.sqrt = stoi(top.substr(top.find("") + 3));
72-
string num = top.substr(0, top.find(""));
70+
if (top.find(SQRT_CH) != string::npos) {
71+
m.sqrt = stoi(top.substr(top.find(SQRT_CH) + SQRT_LEN));
72+
string num = top.substr(0, top.find(SQRT_CH));
7373
if (num.length() == 0) m.numerator = 1;
7474
else if (num.length() == 1 && num[0] == '-') m.numerator = -1;
7575
else m.numerator = stoi(num);

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int main () {
44
cin.sync_with_stdio(false);
5-
cout << "Square Root: " << endl;
5+
cout << "Square Root: " << SQRT_CH << endl;
66
process_expressions();
77
return 0;
88
}

0 commit comments

Comments
 (0)