/* Generated by Nim Compiler v1.3.5 */
/*   (c) 2020 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64

/* section: NIM_merge_HEADERS */

#include "nimbase.h"
#include <string.h>
#include <stdio.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

/* section: NIM_merge_FRAME_DEFINES */
#define nimfr_(x, y)
#define nimln_(x, y)

/* section: NIM_merge_FORWARD_TYPES */
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;

/* section: NIM_merge_TYPES */
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef NU8 tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA;

/* section: NIM_merge_PROC_HEADERS */
N_LIB_PRIVATE N_NIMCALL(tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA, classify__x3IKzrz1VNvfZbypScSTXg)(NF x);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem__i80o3k0SgEI5gTRCzYdyWAsystem)(void* dest, void* source, NI size);
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newLen);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);

/* section: NIM_merge_DATA */
STRING_LITERAL(TM__mZLUkjbotQF2WK9bQcNKBCA_2, "NAN", 3);
STRING_LITERAL(TM__mZLUkjbotQF2WK9bQcNKBCA_3, "-0.0", 4);
STRING_LITERAL(TM__mZLUkjbotQF2WK9bQcNKBCA_4, "0.0", 3);
STRING_LITERAL(TM__mZLUkjbotQF2WK9bQcNKBCA_5, "INF", 3);
STRING_LITERAL(TM__mZLUkjbotQF2WK9bQcNKBCA_6, "-INF", 4);

/* section: NIM_merge_VARS */
extern NIM_BOOL nimInErrorMode__759bT87luu8XGcbkw13FUjA;

/* section: NIM_merge_PROCS */
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest, source, ((size_t) (size)));
}
static N_INLINE(void, copyMem__i80o3k0SgEI5gTRCzYdyWAsystem)(void* dest, void* source, NI size) {
	nimCopyMem(dest, source, size);
}
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	{
		void* T5_;
		void* T6_;
		if (!!((src == NIM_NIL))) goto LA3_;
		T5_ = (void*)0;
		T5_ = ((void*) ((&(*dest).data[(*dest).Sup.len])));
		T6_ = (void*)0;
		T6_ = ((void*) ((*src).data));
		copyMem__i80o3k0SgEI5gTRCzYdyWAsystem(T5_, T6_, ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
		(*dest).Sup.len += (*src).Sup.len;
	}
	LA3_: ;
}
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s) {
	NCSTRING result;
	result = (NCSTRING)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (s == NIM_NIL);
		if (T3_) goto LA4_;
		T3_ = ((*s).Sup.len == ((NI) 0));
		LA4_: ;
		if (!T3_) goto LA5_;
		result = "";
	}
	goto LA1_;
	LA5_: ;
	{
		result = ((NCSTRING) ((*s).data));
	}
	LA1_: ;
	return result;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (NIM_BOOL*)0;
	result = (&nimInErrorMode__759bT87luu8XGcbkw13FUjA);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, toStrMaxPrecision__ayHojnbqAtgkZF8TXMNMzg)(NF f, NimStringDesc* literalPostfix) {
	NimStringDesc* result;
	tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NimStringDesc*)0;
	T1_ = (tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA)0;
	T1_ = classify__x3IKzrz1VNvfZbypScSTXg(f);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	switch (T1_) {
	case ((tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA) 4):
	{
		result = copyString(((NimStringDesc*) &TM__mZLUkjbotQF2WK9bQcNKBCA_2));
	}
	break;
	case ((tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA) 3):
	{
		NimStringDesc* T4_;
		T4_ = (NimStringDesc*)0;
		T4_ = rawNewString((literalPostfix ? literalPostfix->Sup.len : 0) + 4);
appendString(T4_, ((NimStringDesc*) &TM__mZLUkjbotQF2WK9bQcNKBCA_3));
appendString(T4_, literalPostfix);
		result = T4_;
	}
	break;
	case ((tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA) 2):
	{
		NimStringDesc* T6_;
		T6_ = (NimStringDesc*)0;
		T6_ = rawNewString((literalPostfix ? literalPostfix->Sup.len : 0) + 3);
appendString(T6_, ((NimStringDesc*) &TM__mZLUkjbotQF2WK9bQcNKBCA_4));
appendString(T6_, literalPostfix);
		result = T6_;
	}
	break;
	case ((tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA) 5):
	{
		result = copyString(((NimStringDesc*) &TM__mZLUkjbotQF2WK9bQcNKBCA_5));
	}
	break;
	case ((tyEnum_FloatClass__pPga1yW9b8J9cwNnm9b1aPRnA) 6):
	{
		result = copyString(((NimStringDesc*) &TM__mZLUkjbotQF2WK9bQcNKBCA_6));
	}
	break;
	default:
	{
		int n;
		NimStringDesc* T10_;
		result = mnewString(((NI) 81));
		T10_ = (NimStringDesc*)0;
		T10_ = result;
		n = snprintf(nimToCStringConv(T10_), ((NU) ((result ? result->Sup.len : 0))), "%#.16e%s", f, nimToCStringConv(literalPostfix));
		result = setLengthStr(result, ((NI) (n)));
	}
	break;
	}
	}BeforeRet_: ;
	return result;
}
