File tree 1 file changed +46
-1
lines changed
1 file changed +46
-1
lines changed Original file line number Diff line number Diff line change 94
94
}
95
95
96
96
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97
- % Math
97
+ % Arithmetic
98
98
%
99
99
100
+ \cs _new_protected:Nn \fracmath _prepare:N
101
+ {
102
+ \prop _put_if_new:Nnn #1 { integer } { 0 }
103
+ \prop _put_if_new:Nnn #1 { numerator } { 0 }
104
+ \prop _put_if_new:Nnn #1 { denominator } { 1 }
105
+ }
106
+
107
+ \cs _new_protected:Nn \fracmath _garithmetic:NnN
108
+ {
109
+ \prop _if_exist:NF #1 {
110
+ \prop _gclear_new:N #1
111
+ }
112
+ \fracmath _prepare:N #1
113
+ \fracmath _prepare:N #3
114
+
115
+ \regex _match_case:nn {
116
+ { \A \+ \Z } { \fracmath _gadd:NN #1 #3 }
117
+ } { #2 }
118
+ }
119
+ \cs _generate_variant:Nn \fracmath _garithmetic:NnN
120
+ {
121
+ cnN, cVN
122
+ }
123
+
124
+ % Adds two a fractional numbers
125
+ \cs _new_protected:Nn \fracmath _gadd:NN
126
+ {
127
+ \int _zero_new:N \l __fracmath_tmp_value_int
128
+ \int _set:Nn \l __fracmath_tmp_value_int {
129
+ \prop _item:Nn #1 { integer } + \prop _item:Nn #2 { integer }
130
+ }
131
+ \prop _gput:NnV #1 { integer } \l __fracmath_tmp_value_int
132
+
133
+ \int _set:Nn \l __fracmath_tmp_value_int {
134
+ ( \prop _item:Nn #1 { numerator } * \prop _item:Nn #2 { denominator } ) +
135
+ ( \prop _item:Nn #2 { numerator } * \prop _item:Nn #1 { denominator } )
136
+ }
137
+ \prop _gput:NnV #1 { numerator } \l __fracmath_tmp_value_int
138
+
139
+ \int _set:Nn \l __fracmath_tmp_value_int {
140
+ \prop _item:Nn #1 { denominator } * \prop _item:Nn #2 { denominator }
141
+ }
142
+ \prop _gput:NnV #1 { denominator } \l __fracmath_tmp_value_int
143
+ }
144
+
100
145
% Reduces a value, eg 1 6/4 => 2 1/2
101
146
\cs _new_protected:Nn \fracmath _reduce:N
102
147
{
You can’t perform that action at this time.
0 commit comments