// filename:c2011-F-10-3-12-ex.c
// original examples and/or notes:
// 		(c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011
// http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
// 			C2011 F.10.3.12 The modf functions
// compile and output mechanism:
// 		(c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.xx, 2013
// compile errors and/or wornings:
// 1	(c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
// 			Target: x86_64-apple-darwin11.4.2 //Thread model: posix
// 		(c) LLVM 2003-2009 University of Illinois at Urbana-Champaign.
// 2    gcc-4.9 (GCC) 4.9.0 20131229 (experimental)
//      Copyright (C) 2013 Free Software Foundation, Inc.
#include <stdio.h>
#include <math.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS ON
double modf_a(double value, double *iptr)
{
int save_round = fegetround();
fesetround(FE_TOWARDZERO);
*iptr = nearbyint(value);
fesetround(save_round);
return copysign(
isinf(value) ? 0.0 :
value - (*iptr), value);
}
	#define MAX 3
int main(){
	double value[]={3.14159,-2.5, 0.0 /*FP_INFINITE,FP_NAN*/ },ret,ret_a,*iptr,*iptr_a;
	for(int i=0;i<MAX;i++){
		ret = modf(value[i],iptr);
//		ret_a = modf_a(value[i], iptr_a );
		
   	printf("modf( %f, exp ) = %f, exp = %d, modf_a(,) = %f exp_a=%d , true=%d\n", value[i], ret, *iptr,ret_a,*iptr_a,((ret==ret_a) && (*iptr==*iptr_a)) );
	}
	return printf("\nF.10.3.12 The modf functions\n");
}
// if input is
// 123
// then output will be 
// 2 2 23 3 
//5.1.2.3 Program execution, Example7
