bool Or ( bool a, bool b ){ return a ? a : b; } bool And ( bool a, bool b ){ return a ? b : false; } bool Xor ( bool a, bool b ){ return And(a,b) ? false: Or(a,b); }
bool Or ( bool a, bool b ){ return a | b; }bool Xor ( bool a, bool b ){ return a ^ b; }bool And ( bool a, bool b ){ return a & b; }- bool Or ( bool a, bool b ){ return a ? a : b; }
- bool And ( bool a, bool b ){ return a ? b : false; }
- bool Xor ( bool a, bool b ){ return And(a,b) ? false: Or(a,b); }
Fundamentals
-[------->+<]>-.-[->+++++<]>++.+++++++..+++.[--->+<]>-----.+++[->++<]>+.-[------>+<]>.+.[--->+<]>----.---------.----.+++++++.
>++++++[<++++++++++++>-]<.>>++++++++++[<++++++++++>-]<+.+++++++..+++.>>++++[<++++++++>-]<.<<-.>--------------.+.++++++++++++++++.---------.----.+++++++.- -[------->+<]>-.-[->+++++<]>++.+++++++..+++.[--->+<]>-----.+++[->++<]>+.-[------>+<]>.+.[--->+<]>----.---------.----.+++++++.
inline float multiply(float number1, float number2 ) { float answer = 0; while( number2 > 0 ) { answer += number1; number2--; } return answer; } float squared(float number) { if( number < 0 ) number = -number; int decimal_positions = 0; while( number - int(number) > 0.1 ) { number = multiply(number, 10); decimal_positions++; } float factor = number; if( decimal_positions > 0 ) { number = multiply(number,number); switch (decimal_positions){ case 1: factor = 0.01; break; case 2: factor = 0.001; break; case 3: factor = 0.0001; break; case 4: factor = 0.00001; }} return multiply(factor,number); }
inline int multiply(int x, int y, int counter)- inline float multiply(float number1, float number2 )
- {
if (y <= 0)return 0;if (y == 1)return x;if (y & 0x1)return x + multiply(x, y - 1, 0);if (counter + counter <= y)return multiply(x + x, y >> 1, counter + counter);elsereturn x + multiply(x, y - counter, 0);- float answer = 0;
- while( number2 > 0 )
- {
- answer += number1;
- number2--;
- }
- return answer;
- }
int squared(int number)- float squared(float number)
- {
return multiply(number, number, 0);- if( number < 0 ) number = -number;
- int decimal_positions = 0;
- while( number - int(number) > 0.1 )
- {
- number = multiply(number, 10);
- decimal_positions++;
- }
- float factor = number;
- if( decimal_positions > 0 ) {
- number = multiply(number,number);
- switch (decimal_positions){
- case 1: factor = 0.01; break;
- case 2: factor = 0.001; break;
- case 3: factor = 0.0001; break;
- case 4: factor = 0.00001;
- }}
- return multiply(factor,number);
- }
Describe(squared_tests) { It(squared0_is0) { Assert::That(squared(0), Equals(0)); } It(squaredNegative0Dot5_is0Dot25) { Assert::That(squared(-0.5), EqualsWithDelta(0.25, 0.00001)); } It(squared1_is1) { Assert::That(squared(1), Equals(1)); } It(squared2_is4) { Assert::That(squared(2), Equals(4)); } It(squared3_is9) { Assert::That(squared(3), Equals(9)); } It(squared4_is16) { Assert::That(squared(4), Equals(16)); } It(squared10_is100) { Assert::That(squared(10), Equals(100)); } It(squared15_is225) { Assert::That(squared(15), Equals(225)); } It(squared21_is441) { Assert::That(squared(21), Equals(441)); } It(squared101_is10201) { Assert::That(squared(101), Equals(10201)); } };
- Describe(squared_tests)
- {
- It(squared0_is0)
- {
- Assert::That(squared(0), Equals(0));
- }
- It(squaredNegative0Dot5_is0Dot25)
- {
- Assert::That(squared(-0.5), EqualsWithDelta(0.25, 0.00001));
- }
- It(squared1_is1)
- {
- Assert::That(squared(1), Equals(1));
- }
- It(squared2_is4)
- {
- Assert::That(squared(2), Equals(4));
- }
- It(squared3_is9)
- {
- Assert::That(squared(3), Equals(9));
- }
- It(squared4_is16)
- {
- Assert::That(squared(4), Equals(16));
- }
- It(squared10_is100)
- {
- Assert::That(squared(10), Equals(100));
- }
- It(squared15_is225)
- {
- Assert::That(squared(15), Equals(225));
- }
- It(squared21_is441)
- {
- Assert::That(squared(21), Equals(441));
- }
- It(squared101_is10201)
- {
- Assert::That(squared(101), Equals(10201));
- }
- };