/*	Copyright  (c)	Günter Woigk 2018 - 2020
					mailto:kio@little-bat.de

	This file is free software.

	Permission to use, copy, modify, distribute, and sell this software
	and its documentation for any purpose is hereby granted without fee,
	provided that the above copyright notice appears in all copies and
	that both that copyright notice, this permission notice and the
	following disclaimer appear in supporting documentation.

	THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY,
	NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
	A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE COPYRIGHT HOLDER
	BE LIABLE FOR ANY DAMAGES ARISING FROM THE USE OF THIS SOFTWARE,
	TO THE EXTENT PERMITTED BY APPLICABLE LAW.
*/

#pragma once
#include <limits>
#include "kio/kio.h"


extern uint32	lineForPos (cstr source, uint32 spos) noexcept;
extern uint		numCPUs() noexcept;			// os_utilities.cpp

static constexpr float128 minint8 = std::numeric_limits<int8>::min();
static constexpr float128 maxint8 = std::numeric_limits<int8>::max();
static constexpr float128 maxuint8 = std::numeric_limits<uint8>::max();
static constexpr float128 minint16 = std::numeric_limits<int16>::min();
static constexpr float128 maxint16 = std::numeric_limits<int16>::max();
static constexpr float128 maxuint16 = std::numeric_limits<uint16>::max();
static constexpr float128 minint32 = std::numeric_limits<int32>::min();
static constexpr float128 maxint32 = std::numeric_limits<int32>::max();
static constexpr float128 maxuint32 = std::numeric_limits<uint32>::max();
static constexpr float128 minint64 = std::numeric_limits<int64>::min();
static constexpr float128 maxint64 = std::numeric_limits<int64>::max();
static constexpr float128 maxuint64 = std::numeric_limits<uint64>::max();

inline uint bitsForSize (uint64 n)
{
	// return 8, 16, 32 or 64
	return n>>16 ? n>>32 ? 64 : 32 : n>>8  ? 16 : 8;
}

inline uint bitsForSize (int64 n)
{
	// return 8, 16, 32 or 64
	if(n<0) n = ~n;
	return n>>15 ? n>>31 ? 64 : 32 : n>>7  ? 16 : 8;
}

extern uint32 tou32 (cptr s, uint32 min, uint32 max, cstr name) throws; // AnyError













