ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since 9b34766 was             200fcb3, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago           | 
        
        
          | 
             
add auto newline to sout, change endl to nl 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            484 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | #include <fstream.hfa>
 | 
|---|
| 2 | 
 | 
|---|
| 3 | // [unsigned, unsigned] offset_to_index(unsigned offset, unsigned sx, unsigned sy)
 | 
|---|
| 4 | // {
 | 
|---|
| 5 | //     return [offset / sx, offset % sy];
 | 
|---|
| 6 | // }
 | 
|---|
| 7 | 
 | 
|---|
| 8 | forall(otype index_t)
 | 
|---|
| 9 | index_t offset_to_index(unsigned offset, index_t size) {
 | 
|---|
| 10 |     return [offset / size.0, offset % size.1];
 | 
|---|
| 11 | }
 | 
|---|
| 12 | 
 | 
|---|
| 13 | int main(int argc, char* argv[]) {
 | 
|---|
| 14 |     unsigned x = 0, y = 0, i = 0;
 | 
|---|
| 15 |     unsigned sx = 4, sy = 4;
 | 
|---|
| 16 | 
 | 
|---|
| 17 |     i = 6;
 | 
|---|
| 18 |     [x, y] = offset_to_index(6, [sx, sy]);
 | 
|---|
| 19 | 
 | 
|---|
| 20 |     sout | x | ' ' | y;
 | 
|---|
| 21 | 
 | 
|---|
| 22 |     return 0;
 | 
|---|
| 23 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.