#include <iostream>
#include <math.h>
using namespace std;

struct Vec4Ni10w2;

struct Vec4f32
{
	float x, y, z, w;

	Vec4f32(float x, float y, float z, float w) :
		x(x), y(y), z(z), w(w)
	{
	}

	Vec4f32(const Vec4Ni10w2 &v);
};

struct Vec4Ni10w2
{
	int x : 10;
	int y : 10;
	int z : 10;
	int w : 2;

	Vec4Ni10w2(const Vec4f32 &v) :
		x(round(511 * v.x)), y(round(511 * v.y)), z(round(511 * v.z)), w(round(v.w))
	{
	}
};

Vec4f32::Vec4f32(const Vec4Ni10w2 &v) :
	x((float)v.x / 511), y((float)v.y / 511), z((float)v.z / 511), w((float)v.w)
{
}

ostream& operator <<(ostream& out, const Vec4f32 &v)
{
	return out << "(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
}

ostream& operator <<(ostream& out, const Vec4Ni10w2 &v)
{
	return out << "(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
}

int main() {
	static_assert(sizeof(Vec4Ni10w2) == 4, "неверный размер Vec4Ni10w2");
	
	Vec4f32 orig(0.2, -0.4, 0.6, -0.8);
	cout << "Исходный float32-вектор: " << orig << endl;

	Vec4Ni10w2 denorm(orig);
	cout << "Денормализованный в INT_10_10_10_2: " << denorm << endl;

	Vec4f32 back(denorm);
	cout << "Преобразованный назад во float32: " << back << endl;

	return 0;
}