Fix add_num_to_str to accept arbitrary length numbers
This commit is contained in:
		
							parent
							
								
									9fcf19383c
								
							
						
					
					
						commit
						ccb5741666
					
				| @ -42,7 +42,7 @@ Currently missing big features (TODOs) are: | |||||||
| - ~~Unary operators~~ | - ~~Unary operators~~ | ||||||
| - ~~Floats~~ (DONE) | - ~~Floats~~ (DONE) | ||||||
| - ~~Type casting~~ (DONE) | - ~~Type casting~~ (DONE) | ||||||
| - Built-in Int/Float division and modulo | - ~~Built-in Int/Float division and modulo~~ | ||||||
| - Loops | - Loops | ||||||
| - Debug Information (PARTIALLY DONE) | - Debug Information (PARTIALLY DONE) | ||||||
| - Ability to specify types in literals and variable definitions | - Ability to specify types in literals and variable definitions | ||||||
|  | |||||||
| @ -10,7 +10,7 @@ fn main() -> i32 { | |||||||
| 
 | 
 | ||||||
|     add_char(&mut test, '!'); |     add_char(&mut test, '!'); | ||||||
|     set_char(&mut test, 'B', 0); |     set_char(&mut test, 'B', 0); | ||||||
|     add_num_to_str(&mut test, 7); |     add_num_to_str(&mut test, 1234); | ||||||
|      |      | ||||||
|     print(&test); |     print(&test); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -93,14 +93,19 @@ fn str_length(string: *char, position: u32) -> u32 { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn add_num_to_str(string: &mut String, num: u64) { | pub fn add_num_to_str(string: &mut String, num: u64) { | ||||||
|     if num == 0 { add_char(string, '0'); }  |     if num > 10 { | ||||||
|     else if num == 1 { add_char(string, '1'); } |         add_num_to_str(string, num / 10) | ||||||
|     else if num == 2 { add_char(string, '2'); } |     } | ||||||
|     else if num == 3 { add_char(string, '3'); } |     let rem = num % 10; | ||||||
|     else if num == 4 { add_char(string, '4'); } | 
 | ||||||
|     else if num == 5 { add_char(string, '5'); } |     if rem == 0 { add_char(string, '0'); }  | ||||||
|     else if num == 6 { add_char(string, '6'); } |     else if rem == 1 { add_char(string, '1'); } | ||||||
|     else if num == 7 { add_char(string, '7'); } |     else if rem == 2 { add_char(string, '2'); } | ||||||
|     else if num == 8 { add_char(string, '8'); } |     else if rem == 3 { add_char(string, '3'); } | ||||||
|     else if num == 9 { add_char(string, '9'); } |     else if rem == 4 { add_char(string, '4'); } | ||||||
|  |     else if rem == 5 { add_char(string, '5'); } | ||||||
|  |     else if rem == 6 { add_char(string, '6'); } | ||||||
|  |     else if rem == 7 { add_char(string, '7'); } | ||||||
|  |     else if rem == 8 { add_char(string, '8'); } | ||||||
|  |     else if rem == 9 { add_char(string, '9'); } | ||||||
| } | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user