added fallback code for math::round()
This commit is contained in:
		| @ -155,7 +155,45 @@ static qse_awk_flt_t math_round (qse_awk_t* awk, qse_awk_flt_t x) | ||||
| #elif defined(HAVE_ROUNDF) | ||||
| 	return roundf (x); | ||||
| #else | ||||
| 	#error ### no round function available ### | ||||
|  | ||||
| 	qse_flt_t f, d; | ||||
|  | ||||
| 	f = math_floor (awk, x); | ||||
| 	d = x - f; /* get fraction */ | ||||
|  | ||||
| 	if (d > (qse_awk_flt_t)0.5) | ||||
| 	{ | ||||
| 		/* round up to the nearest */ | ||||
| 		f =  f + (qse_awk_flt_t)1.0; | ||||
| 	} | ||||
| 	else if (d == (qse_awk_flt_t)0.5) | ||||
| 	{ | ||||
| 	#if 1 | ||||
| 		/* round half away from zero */ | ||||
| 		if (x >= 0) | ||||
| 		{ | ||||
| 			f = x + (qse_awk_flt_t)0.5; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			f = x - (qse_awk_flt_t)0.5; | ||||
| 		} | ||||
| 	#else | ||||
| 		/* round half to even - C99's rint() does this, i guess. */ | ||||
| 		d = f - (qse_awk_flt_t)2.0 * math_floor(awk, f * (qse_awk_flt_t)0.5); | ||||
| 		if (d == (qse_awk_flt_t)1.0) f =  f + (qse_awk_flt_t)1.0; | ||||
| 	#endif | ||||
| 	} | ||||
|  | ||||
| 	/* this implementation doesn't keep the signbit for -0.0. | ||||
| 	 * The signbit() function defined in C99 may get used to | ||||
| 	 * preserve the sign bit. but this is a fall-back rountine | ||||
| 	 * for a system without round also defined in C99.  | ||||
| 	 * don't get annoyed by the lost sign bit for the value of 0.0. | ||||
| 	 */ | ||||
|  | ||||
| 	return f; | ||||
| 	 | ||||
| #endif | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -119,7 +119,11 @@ static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs) | ||||
| 		httpd->opt.rcb.logact (httpd, &msg); | ||||
| 	} | ||||
|  | ||||
| #if defined(IPPROTO_SCTP) | ||||
| 	type = (proto == IPPROTO_SCTP)? SOCK_SEQPACKET: SOCK_DGRAM; | ||||
| #else | ||||
| 	type = SOCK_DGRAM; | ||||
| #endif | ||||
| 	 | ||||
| 	urs->handle[0].i = open_udp_socket (httpd, AF_INET, type, proto); | ||||
| #if defined(AF_INET6) | ||||
|  | ||||
| @ -430,8 +430,11 @@ static QSE_INLINE qse_ssize_t __send_file ( | ||||
| 	#endif | ||||
| 	size_t xfer; | ||||
| 	ssize_t ret; | ||||
| 	qse_fio_hnd_t fh; | ||||
|  | ||||
| 	vec.sfv_fd = in_fd.i; | ||||
| 	fh = qse_fio_gethandle(in_fd.ptr); | ||||
|  | ||||
| 	vec.sfv_fd = fh; | ||||
| 	vec.sfv_flag = 0; | ||||
| 	if (offset) | ||||
| 	{ | ||||
| @ -439,7 +442,7 @@ static QSE_INLINE qse_ssize_t __send_file ( | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		vec.sfv_off = QSE_LSEEK (in_fd.i, 0, SEEK_CUR);  | ||||
| 		vec.sfv_off = QSE_LSEEK (fh, 0, SEEK_CUR);  | ||||
| 		if (vec.sfv_off == (off_t)-1) return (qse_ssize_t)-1; | ||||
| 	} | ||||
| 	vec.sfv_len = count; | ||||
| @ -739,9 +742,10 @@ static qse_sck_hnd_t open_udp_socket (qse_httpd_t* httpd, int domain, int type, | ||||
|  | ||||
| 	if (set_socket_nonblock (httpd, fd, 1) <= -1) goto oops; | ||||
|  | ||||
| 	#if defined(IPPROTO_SCTP) | ||||
| 	if (proto == IPPROTO_SCTP) | ||||
| 	{ | ||||
| 	#if defined(SOL_SCTP) | ||||
| 		#if defined(SOL_SCTP) | ||||
| 		struct sctp_initmsg im; | ||||
| 		struct sctp_paddrparams hb; | ||||
|  | ||||
| @ -758,8 +762,9 @@ static qse_sck_hnd_t open_udp_socket (qse_httpd_t* httpd, int domain, int type, | ||||
| 		hb.spp_pathmaxrxt = 1; | ||||
|  | ||||
| 		if (setsockopt (fd, SOL_SCTP, SCTP_PEER_ADDR_PARAMS, &hb, QSE_SIZEOF(hb)) <= -1) goto oops; | ||||
| 	#endif | ||||
| 		#endif | ||||
| 	} | ||||
| 	#endif | ||||
|  | ||||
| 	return fd; | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user