|
From: Іван М. С. <iim...@gm...> - 2026-10-19 07:33:38
|
Dear developers of GNUPLOT! In my work, I use the GNUPLOT Version 5.0 patchlevel 7 in which the function frac(x) is missing, and for the functions int(x) and floor(x) there exists an Upper Bound UB = 2**31 = 2,147,483,648, which means these functions do not work when abs(x) > UB. Hence, simply defined function frac(x)=x-int(x) and its analogue fraf(x)=x-floor(x) calculate the fractional part of numbers with small errors only when abs(x) < UB. In many cases, the accuracy of these functions across the entire range of real numbers is extremely important. For example, the current Terrestrial Time frequently used by astronomores is about 1,792,400,000 seconds and is close to the UB number, while one often measures time with accuracy of 0.00001 seconds. Hence accurately working function "frac" would be very useful. I am attaching files illustrating the issue for two versions of Gnuplot: Testing_results_frac_GNU_5_pl_7.txt and Testing_results_frac_GNU_6_pl_5.txt for GNUPLOT 5.0 patchlevel 7 and GNUPLOT 6.0 patchlevel 5. In the former case, the frac(x) strongly fails for x with abs(x) > UB. In the latter case, the frac(x) in this newer Gnuplot operates better; however, one can see that it sill has unacceptably large roundoff errors for large x. I have attempted to address these shortcomings by modernizing existing functions and creating a new one. The program script and an example of its operation are provided at the end of this letter and illustrate these changes. The modernized and newly created functions - INT(x), FLOOR(x), and FRAC() - have been comprehensively tested and operate without errors. I would like to ask that you consider the above when fixing bugs in the old version and creating a new version of Gnuplot. Please let me know about receiving this letter. Sincerely, Physicist-Astronomer Motrunich Ivan I. =========================================================================================== # program for modernizing functions int(x) and floor(x) and creating new function FRAC(x) set macros UB=2**31 # the new constant - Upper Bound of the functions int(x) and floor(x) frac(x)=x-int(x) # old (bad) function frac(x) - does not work properly when abs(x) >= UB N="int(x/UB)*UB" ain(x,y)=int(x-y)+y # the auxiliary function for new function INT(x) INT(x)=abs(x)<UB?int(x):ain(x,@N) # the new modified function INT(x) FLOOR(x)=INT(x)-(x<0?1:0) # the new modified function FLOOR(x) O="10.**int(log10(4e15/x))" p(x,y)=INT(sgn(x)*.5+(x-INT(x))*y)/y # the auxiliary function for new function FRAC(x) FRAC(x)=abs(x)<1?x:p(x,@O) # the new function FRAC(x) # The new functions operate without errors across the entire range of numbers. pr ' PROGRAM TEST FOR POSITIVE NUMBERS' sn=1.06; mn=87654321.54; su=UB-4.37; bu=UB+4.37; bn=123456789012.23; bp=pi*1e13 pr 'inp numb> ',sn,pi,mn,su,bu,bn,bp pr ' int-> ',int(sn),int(pi),int(mn),int(su),int(bu),int(bn),int(bp) pr ' INT-> ',INT(sn),INT(pi),INT(mn),INT(su),INT(bu),INT(bn),INT(bp) pr ' floor-> ',floor(sn),floor(pi),floor(mn),floor(su),floor(bu),floor(bn),floor(bp) pr ' FLOOR-> ',FLOOR(sn),FLOOR(pi),FLOOR(mn),FLOOR(su),FLOOR(bu),FLOOR(bn),FLOOR(bp) pr ' frac-> ',frac(sn),frac(pi),frac(mn),frac(su),frac(bu),frac(bn),frac(bp) pr ' FRAC-> ',FRAC(sn),FRAC(pi),FRAC(mn),FRAC(su),FRAC(bu),FRAC(bn),FRAC(bp) pr ' PROGRAM TEST FOR NEGATIVE NUMBERS' pr 'inp numb> ',-sn,-pi,-mn,-su,-bu,-bn,-bp pr ' int-> ',int(-sn),int(-pi),int(-mn),int(-su),int(-bu),int(-bn),int(-bp) pr ' INT-> ',INT(-sn),INT(-pi),INT(-mn),INT(-su),INT(-bu),INT(-bn),INT(-bp) pr ' floor-> ',floor(-sn),floor(-pi),floor(-mn),floor(-su),floor(-bu),floor(-bn),floor(-bp) pr ' FLOOR-> ',FLOOR(-sn),FLOOR(-pi),FLOOR(-mn),FLOOR(-su),FLOOR(-bu),FLOOR(-bn),FLOOR(-bp) pr ' frac-> ',frac(-sn),frac(-pi),frac(-mn),frac(-su),frac(-bu),frac(-bn),frac(-bp) pr ' FRAC-> ',FRAC(-sn),FRAC(-pi),FRAC(-mn),FRAC(-su),FRAC(-bu),FRAC(-bn),FRAC(-bp) |