/* Generated by Nim Compiler v2.2.10 */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <math.h>
#include <string.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
typedef NU8 tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw;
N_LIB_PRIVATE N_NIMCALL(tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw, classify__pureZmath_u211)(NF x_p0);
static N_INLINE(NIM_BOOL, signbit__astyaml_u680)(NF x_p0);
N_LIB_PRIVATE N_NIMCALL(void, addFloatRoundtrip__system_u4739)(NimStringV2* result_p0, NF x_p1);
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1);
static N_INLINE(void, copyMem__system_u1742)(void* dest_p0, void* source_p1, NI size_p2);
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2);
N_LIB_PRIVATE N_NIMCALL(void, prepareAdd)(NimStringV2* s_p0, NI addLen_p1);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
static N_INLINE(NIM_BOOL, signbit__cgen_u20205)(NF32 x_p0);
N_LIB_PRIVATE N_NIMCALL(void, addFloatRoundtrip__systemZrepr95v2_u97)(NimStringV2* result_p0, NF32 x_p1);
static const struct {
  NI cap; NIM_CHAR data[4+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_2 = { 4 | NIM_STRLIT_FLAG, "-NAN" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_3 = {4, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_2};
static const struct {
  NI cap; NIM_CHAR data[3+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_4 = { 3 | NIM_STRLIT_FLAG, "NAN" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_5 = {3, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_4};
static const struct {
  NI cap; NIM_CHAR data[4+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_6 = { 4 | NIM_STRLIT_FLAG, "-0.0" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_7 = {4, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_6};
static const struct {
  NI cap; NIM_CHAR data[3+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_8 = { 3 | NIM_STRLIT_FLAG, "0.0" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_9 = {3, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_8};
static const struct {
  NI cap; NIM_CHAR data[3+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_10 = { 3 | NIM_STRLIT_FLAG, "INF" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_11 = {3, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_10};
static const struct {
  NI cap; NIM_CHAR data[4+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_12 = { 4 | NIM_STRLIT_FLAG, "-INF" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_13 = {4, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_12};
static const struct {
  NI cap; NIM_CHAR data[0+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_14 = { 0 | NIM_STRLIT_FLAG, "" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_15 = {0, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_14};
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_16 = {0, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_14};
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_17 = {4, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_2};
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_18 = {3, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_4};
static const struct {
  NI cap; NIM_CHAR data[5+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_19 = { 5 | NIM_STRLIT_FLAG, "-0.0f" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_20 = {5, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_19};
static const struct {
  NI cap; NIM_CHAR data[4+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_21 = { 4 | NIM_STRLIT_FLAG, "0.0f" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_22 = {4, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_21};
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_23 = {3, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_10};
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_24 = {4, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_12};
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_25 = {0, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_14};
static const struct {
  NI cap; NIM_CHAR data[1+1];
} TM__mZLUkjbotQF2WK9bQcNKBCA_26 = { 1 | NIM_STRLIT_FLAG, "f" };
static const NimStringV2 TM__mZLUkjbotQF2WK9bQcNKBCA_27 = {1, (NimStrPayload*)&TM__mZLUkjbotQF2WK9bQcNKBCA_26};
extern NIM_BOOL nimInErrorMode__system_u4143;
static N_INLINE(NIM_BOOL, signbit__astyaml_u680)(NF x_p0) {
	NIM_BOOL result;
	int T1_;
	T1_ = (int)0;
	T1_ = signbit(x_p0);
	result = !((T1_ == ((NI32)0)));
	return result;
}
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest_p0, source_p1, ((size_t) (size_p2)));
}
static N_INLINE(void, copyMem__system_u1742)(void* dest_p0, void* source_p1, NI size_p2) {
	nimCopyMem(dest_p0, source_p1, size_p2);
}
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1) {
	{
		if (!(((NI)0) < src_p1.len)) goto LA3_;
		copyMem__system_u1742(((void*) ((&(*(*dest_p0).p).data[(*dest_p0).len]))), ((void*) ((&(*src_p1.p).data[((NI)0)]))), (src_p1.len));
		(*dest_p0).len += src_p1.len;
		(*(*dest_p0).p).data[(*dest_p0).len] = 0;
	}
LA3_: ;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4143);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, toStrMaxPrecision__astyaml_u674)(NF f_p0) {
	NimStringV2 result;
	tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	T1_ = (tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)0;
	T1_ = classify__pureZmath_u211(f_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	switch (T1_) {
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)4):
	{
		{
			NIM_BOOL T5_;
			T5_ = (NIM_BOOL)0;
			T5_ = signbit__astyaml_u680(f_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (!T5_) goto LA6_;
			result = TM__mZLUkjbotQF2WK9bQcNKBCA_3;
		}
		goto LA3_;
LA6_: ;
		{
			result = TM__mZLUkjbotQF2WK9bQcNKBCA_5;
		}
LA3_: ;
	}
	break;
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)3):
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_7;
	}
	break;
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)2):
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_9;
	}
	break;
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)5):
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_11;
	}
	break;
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)6):
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_13;
	}
	break;
	default:
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_15;
		addFloatRoundtrip__system_u4739((&result), f_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		prepareAdd((&result), 0);
appendString((&result), TM__mZLUkjbotQF2WK9bQcNKBCA_16);
	}
	break;
	}
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NIM_BOOL, signbit__cgen_u20205)(NF32 x_p0) {
	NIM_BOOL result;
	int T1_;
	T1_ = (int)0;
	T1_ = signbit(x_p0);
	result = !((T1_ == ((NI32)0)));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, toStrMaxPrecision__cgen_u20199)(NF32 f_p0) {
	NimStringV2 result;
	tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	T1_ = (tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)0;
	T1_ = classify__pureZmath_u211(((NF) (f_p0)));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	switch (T1_) {
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)4):
	{
		{
			NIM_BOOL T5_;
			T5_ = (NIM_BOOL)0;
			T5_ = signbit__cgen_u20205(f_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (!T5_) goto LA6_;
			result = TM__mZLUkjbotQF2WK9bQcNKBCA_17;
		}
		goto LA3_;
LA6_: ;
		{
			result = TM__mZLUkjbotQF2WK9bQcNKBCA_18;
		}
LA3_: ;
	}
	break;
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)3):
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_20;
	}
	break;
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)2):
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_22;
	}
	break;
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)5):
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_23;
	}
	break;
	case ((tyEnum_FloatClass__gfrWEZTSUZU5OWgwK4wTYw)6):
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_24;
	}
	break;
	default:
	{
		result = TM__mZLUkjbotQF2WK9bQcNKBCA_25;
		addFloatRoundtrip__systemZrepr95v2_u97((&result), f_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		prepareAdd((&result), 1);
appendString((&result), TM__mZLUkjbotQF2WK9bQcNKBCA_27);
	}
	break;
	}
	}BeforeRet_: ;
	return result;
}
