//
// Copyright (c) 2009 Froduald Kabanza and the Université de Sherbrooke.
// Use of this software is permitted for non-commercial research purposes, and
// it may be copied or applied only for that use. All copies must include this
// copyright message.
// 
// This is a research prototype that has not gone through intensive tests and
// is delivered as is. It may still contain bugs. Froduald Kabanza and the
// Université de Sherbrooke disclaim any responsibility for damage that may be
// caused by using it.
//
// Implementation: Simon Chamberland
// Project Manager: Froduald Kabanza
//

#include "stdafx.h"
#include "Utils.h"

#include <sstream>
#include <stdexcept>
#include <string>

std::string stringify(double x)
{
 std::ostringstream o;
 if (!(o << x))
   throw std::runtime_error("stringify(double) failed");
 return o.str();
}

bool getPrimeNumber(size_t i, size_t& primeNumber)
{
  static size_t primeNumbers[] = { 1, 3, 5, 7, 11, 13, 17, 19, 23, 27, 31, 37, 41, 43, 47 };
  static const size_t nbPrimeNumbers = sizeof(primeNumbers) / sizeof(primeNumbers[0]);

  primeNumber = primeNumbers[i % nbPrimeNumbers];

  return i < nbPrimeNumbers;
}