Question: I have a large mutable array with lots of duplicate values in alphabetical order.

I need to be able to convert my array \*Array into a new array that contains one entry for each string variant.

I am currently using:

```
NSArray *array = [NSArray arrayWithObjects:papersObject.paperSubject, nil];

NSCountedSet *paperSet = [[NSCountedSet alloc] initWithArray:array];
NSMutableArray *namesArray = [[NSMutableArray alloc] initWithCapacity:[array count]];

[namesSet enumerateObjectsUsingBlock:^(id obj, BOOL *stop){
    if ([paperSet countForObject:obj] == 1) {
        [namesArray addObject:obj];
    }
}];

NSLog(@"%@", namesArray);

```

But this returns a long list of the same array, still with duplicates.

Any ideas?

Answer: 
I am fairly certain the answer is always going to be "no". 

clock\_gettime won't return with tv\_nsec >= 10e9. clock\_settime() and clock\_nanosleep() both place this restriction on their inputs, so I've always assumed clock\_gettime was consistent with that.

Also on Linux + glibc, if you dig deep enough into glibc, you'll see code like this:

Excerpt from glibc/nptl/pthread\_clock\_gettime.c:

```
/* Compute the seconds.  */
tp->tv_sec = tsc / freq;

/* And the nanoseconds.  This computation should be stable until
   we get machines with about 16GHz frequency.  */
tp->tv_nsec = ((tsc % freq) * 1000000000ull) / freq;

```

This also occurs in glibc/sysdeps/unix/clock\_gettime.c.

But you're right, the man pages don't say. At least not what's in my Linux distro or on opengroup.org. So implementation is technically subject to change w/o warning. 

If you're writing for Linux + glibc, I'd say your safe. You can check alternate open source libc libraries yourself, e.g. Android's bionic, or the scaled down newlib.

If you're targeting some other closed source POSIX system, you or your client are problem paying for support, so ask the vendor if it's not documented.

If trying to be portable as possible and feeling paranoid, wrap clock\_gettime with a "normalizing" function like this:

```
int my_gettime( struct timespec * ts ) 
{  
   int ret; 
   if( 0 == (ret = clock_gettime(SOME_CLOCK, ts))
   {
      while (tv_nsec >= 1000000000 )
      {
         ts->tv_nsec -= 1000000000;
         ts->tv_sec += 1;
      }
   }
   return ret;
}

```
No, you don't need to normalize the result. You can trust the nanoseconds field to be within 0 and 999999999, inclusive.

The POSIX specification for [`clock_gettime()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html) explicitly states that `clock_settime()` will fail with `EINVAL` if `tv_nsec < 0 || tv_nsec >= 1000000000`.

Standards pedants may argue, but simple symmetry alone tells us we can expect the same from `clock_gettime()`. Technically, 10e9 ns is one second, and since the standard consistently uses the term *"seconds and nanoseconds"*, the logical conclusion is that the nanoseconds field is supposed to be normalized. Besides, a lot of programs will glitch out in interesting and fascinating ways if `clock_gettime()` were to return results with nanoseconds field out of bounds.