summaryrefslogtreecommitdiff
path: root/gcc/ada/a-tifiio.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-21 13:42:24 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-21 13:42:24 +0000
commit9dfe12ae5b94d03c997ea2903022a5d2d5c5f266 (patch)
treebdfc70477b60f1220cb05dd233a4570dd9c6bb5c /gcc/ada/a-tifiio.adb
parent1c662558a1113238a624245a45382d3df90ccf13 (diff)
downloadgcc-9dfe12ae5b94d03c997ea2903022a5d2d5c5f266.tar.gz
2003-10-21 Arnaud Charlet <charlet@act-europe.fr>
* 3psoccon.ads, 3veacodu.adb, 3vexpect.adb, 3vsoccon.ads, 3vsocthi.adb, 3vsocthi.ads, 3vtrasym.adb, 3zsoccon.ads, 3zsocthi.adb, 3zsocthi.ads, 50system.ads, 51system.ads, 55system.ads, 56osinte.adb, 56osinte.ads, 56taprop.adb, 56taspri.ads, 56tpopsp.adb, 57system.ads, 58system.ads, 59system.ads, 5aml-tgt.adb, 5bml-tgt.adb, 5csystem.ads, 5dsystem.ads, 5fosinte.adb, 5gml-tgt.adb, 5hml-tgt.adb, 5isystem.ads, 5lparame.adb, 5msystem.ads, 5psystem.ads, 5sml-tgt.adb, 5sosprim.adb, 5stpopsp.adb, 5tsystem.ads, 5usystem.ads, 5vml-tgt.adb, 5vsymbol.adb, 5vtraent.adb, 5vtraent.ads, 5wml-tgt.adb, 5xparame.ads, 5xsystem.ads, 5xvxwork.ads, 5yparame.ads, 5ytiitho.adb, 5zinit.adb, 5zml-tgt.adb, 5zparame.ads, 5ztaspri.ads, 5ztfsetr.adb, 5zthrini.adb, 5ztiitho.adb, 5ztpopsp.adb, 7stfsetr.adb, 7straces.adb, 7strafor.adb, 7strafor.ads, 7stratas.adb, a-excach.adb, a-exexda.adb, a-exexpr.adb, a-exextr.adb, a-exstat.adb, a-strsup.adb, a-strsup.ads, a-stwisu.adb, a-stwisu.ads, bld.adb, bld.ads, bld-io.adb, bld-io.ads, clean.adb, clean.ads, ctrl_c.c, erroutc.adb, erroutc.ads, errutil.adb, errutil.ads, err_vars.ads, final.c, g-arrspl.adb, g-arrspl.ads, g-boubuf.adb, g-boubuf.ads, g-boumai.ads, g-bubsor.adb, g-bubsor.ads, g-comver.adb, g-comver.ads, g-ctrl_c.ads, g-dynhta.adb, g-dynhta.ads, g-eacodu.adb, g-excact.adb, g-excact.ads, g-heasor.adb, g-heasor.ads, g-memdum.adb, g-memdum.ads, gnatclean.adb, gnatsym.adb, g-pehage.adb, g-pehage.ads, g-perhas.ads, gpr2make.adb, gpr2make.ads, gprcmd.adb, gprep.adb, gprep.ads, g-semaph.adb, g-semaph.ads, g-string.adb, g-string.ads, g-strspl.ads, g-wistsp.ads, i-vthrea.adb, i-vthrea.ads, i-vxwoio.adb, i-vxwoio.ads, Makefile.generic, Makefile.prolog, Makefile.rtl, prep.adb, prep.ads, prepcomp.adb, prepcomp.ads, prj-err.adb, prj-err.ads, s-boarop.ads, s-carsi8.adb, s-carsi8.ads, s-carun8.adb, s-carun8.ads, s-casi16.adb, s-casi16.ads, s-casi32.adb, s-casi32.ads, s-casi64.adb, s-casi64.ads, s-casuti.adb, s-casuti.ads, s-caun16.adb, s-caun16.ads, s-caun32.adb, s-caun32.ads, s-caun64.adb, s-caun64.ads, scng.adb, scng.ads, s-exnint.adb, s-exnllf.adb, s-exnlli.adb, s-expint.adb, s-explli.adb, s-geveop.adb, s-geveop.ads, s-hibaen.ads, s-htable.adb, s-htable.ads, sinput-c.adb, sinput-c.ads, s-memcop.ads, socket.c, s-purexc.ads, s-scaval.adb, s-stopoo.adb, s-strcom.adb, s-strcom.ads, s-strxdr.adb, s-rident.ads, s-thread.adb, s-thread.ads, s-tpae65.adb, s-tpae65.ads, s-tporft.adb, s-traent.adb, s-traent.ads, styleg.adb, styleg.ads, styleg-c.adb, styleg-c.ads, s-veboop.adb, s-veboop.ads, s-vector.ads, symbols.adb, symbols.ads, tb-alvms.c, tb-alvxw.c, tempdir.adb, tempdir.ads, vms_conv.ads, vms_conv.adb, vms_data.ads, vxaddr2line.adb: Files added. Merge with ACT tree. * 4dintnam.ads, 4mintnam.ads, 4uintnam.ads, 52system.ads, 5dosinte.ads, 5etpopse.adb, 5mosinte.ads, 5qosinte.adb, 5qosinte.ads, 5qstache.adb, 5qtaprop.adb, 5qtaspri.ads, 5stpopse.adb, 5uintman.adb, 5uosinte.ads, adafinal.c, g-enblsp.adb, io-aux.c, scn-nlit.adb, scn-slit.adb, s-exnflt.ads, s-exngen.adb, s-exngen.ads, s-exnlfl.ads, s-exnlin.ads, s-exnsfl.ads, s-exnsin.ads, s-exnssi.ads, s-expflt.ads, s-expgen.adb, s-expgen.ads, s-explfl.ads, s-explin.ads, s-expllf.ads, s-expsfl.ads, s-expsin.ads, s-expssi.ads, style.adb: Files removed. Merge with ACT tree. * 1ic.ads, 31soccon.ads, 31soliop.ads, 3asoccon.ads, 3bsoccon.ads, 3gsoccon.ads, 3hsoccon.ads, 3ssoccon.ads, 3ssoliop.ads, 3wsoccon.ads, 3wsocthi.adb, 3wsocthi.ads, 3wsoliop.ads, 41intnam.ads, 42intnam.ads, 4aintnam.ads, 4cintnam.ads, 4gintnam.ads, 4hexcpol.adb, 4hintnam.ads, 4lintnam.ads, 4nintnam.ads, 4ointnam.ads, 4onumaux.ads, 4pintnam.ads, 4sintnam.ads, 4vcaldel.adb, 4vcalend.adb, 4vintnam.ads, 4wexcpol.adb, 4wintnam.ads, 4zintnam.ads, 51osinte.adb, 51osinte.ads, 52osinte.adb, 52osinte.ads, 53osinte.ads, 54osinte.ads, 5aosinte.adb, 5aosinte.ads, 5asystem.ads, 5ataprop.adb, 5atasinf.ads, 5ataspri.ads, 5atpopsp.adb, 5avxwork.ads, 5bosinte.adb, 5bosinte.ads, 5bsystem.ads, 5cosinte.ads, 5esystem.ads, 5fintman.adb, 5fosinte.ads, 5fsystem.ads, 5ftaprop.adb, 5ftasinf.ads, 5ginterr.adb, 5gintman.adb, 5gmastop.adb, 5gosinte.ads, 5gproinf.ads, 5gsystem.ads, 5gtaprop.adb, 5gtasinf.ads, 5gtpgetc.adb, 5hosinte.adb, 5hosinte.ads, 5hsystem.ads, 5htaprop.adb, 5htaspri.ads, 5htraceb.adb, 5iosinte.adb, 5itaprop.adb, 5itaspri.ads, 5ksystem.ads, 5kvxwork.ads, 5lintman.adb, 5lml-tgt.adb, 5losinte.ads, 5lsystem.ads, 5mvxwork.ads, 5ninmaop.adb, 5nintman.adb, 5nosinte.ads, 5ntaprop.adb, 5ntaspri.ads, 5ointerr.adb, 5omastop.adb, 5oosinte.adb, 5oosinte.ads, 5oosprim.adb, 5oparame.adb, 5osystem.ads, 5otaprop.adb, 5otaspri.ads, 5posinte.ads, 5posprim.adb, 5pvxwork.ads, 5sintman.adb, 5sosinte.adb, 5sosinte.ads, 5ssystem.ads, 5staprop.adb, 5stasinf.ads, 5staspri.ads, 5svxwork.ads, 5tosinte.ads, 5vasthan.adb, 5vinmaop.adb, 5vinterr.adb, 5vintman.adb, 5vintman.ads, 5vmastop.adb, 5vosinte.adb, 5vosinte.ads, 5vosprim.adb, 5vsystem.ads, 5vtaprop.adb, 5vtaspri.ads, 5vtpopde.adb, 5vtpopde.ads, 5wgloloc.adb, 5wintman.adb, 5wmemory.adb, 5wosprim.adb, 5wsystem.ads, 5wtaprop.adb, 5wtaspri.ads, 5ysystem.ads, 5zinterr.adb, 5zintman.adb, 5zosinte.adb, 5zosinte.ads, 5zosprim.adb, 5zsystem.ads, 5ztaprop.adb, 6vcpp.adb, 6vcstrea.adb, 6vinterf.ads, 7sinmaop.adb, 7sintman.adb, 7sosinte.adb, 7sosprim.adb, 7staprop.adb, 7staspri.ads, 7stpopsp.adb, 7straceb.adb, 9drpc.adb, a-caldel.adb, a-caldel.ads, a-charac.ads, a-colien.ads, a-comlin.adb, adaint.c, adaint.h, ada-tree.def, a-diocst.adb, a-diocst.ads, a-direio.adb, a-except.adb, a-except.ads, a-excpol.adb, a-exctra.adb, a-exctra.ads, a-filico.adb, a-interr.adb, a-intsig.adb, a-intsig.ads, ali.adb, ali.ads, ali-util.adb, ali-util.ads, a-ngcefu.adb, a-ngcoty.adb, a-ngelfu.adb, a-nudira.adb, a-nudira.ads, a-nuflra.adb, a-nuflra.ads, a-reatim.adb, a-reatim.ads, a-retide.ads, a-sequio.adb, a-siocst.adb, a-siocst.ads, a-ssicst.adb, a-ssicst.ads, a-strbou.adb, a-strbou.ads, a-strfix.adb, a-strmap.adb, a-strsea.ads, a-strunb.adb, a-strunb.ads, a-ststio.adb, a-stunau.adb, a-stunau.ads, a-stwibo.adb, a-stwibo.ads, a-stwifi.adb, a-stwima.adb, a-stwiun.adb, a-stwiun.ads, a-tags.adb, a-tags.ads, a-tasatt.adb, a-taside.adb, a-teioed.adb, a-textio.adb, a-textio.ads, a-tienau.adb, a-tifiio.adb, a-tiflau.adb, a-tiflio.adb, a-tigeau.adb, a-tigeau.ads, a-tiinau.adb, a-timoau.adb, a-tiocst.adb, a-tiocst.ads, atree.adb, atree.ads, a-witeio.adb, a-witeio.ads, a-wtcstr.adb, a-wtcstr.ads, a-wtdeio.adb, a-wtedit.adb, a-wtenau.adb, a-wtflau.adb, a-wtinau.adb, a-wtmoau.adb, bcheck.adb, binde.adb, bindgen.adb, bindusg.adb, checks.adb, checks.ads, cio.c, comperr.adb, comperr.ads, csets.adb, cstand.adb, cstreams.c, debug_a.adb, debug_a.ads, debug.adb, decl.c, einfo.adb, einfo.ads, errout.adb, errout.ads, eval_fat.adb, eval_fat.ads, exp_aggr.adb, expander.adb, expander.ads, exp_attr.adb, exp_ch11.adb, exp_ch13.adb, exp_ch2.adb, exp_ch3.adb, exp_ch3.ads, exp_ch4.adb, exp_ch5.adb, exp_ch6.adb, exp_ch7.adb, exp_ch7.ads, exp_ch8.adb, exp_ch9.adb, exp_code.adb, exp_dbug.adb, exp_dbug.ads, exp_disp.adb, exp_dist.adb, expect.c, exp_fixd.adb, exp_imgv.adb, exp_intr.adb, exp_pakd.adb, exp_prag.adb, exp_strm.adb, exp_strm.ads, exp_tss.adb, exp_tss.ads, exp_util.adb, exp_util.ads, exp_vfpt.adb, fe.h, fmap.adb, fmap.ads, fname.adb, fname.ads, fname-uf.adb, fname-uf.ads, freeze.adb, freeze.ads, frontend.adb, g-awk.adb, g-awk.ads, g-busora.adb, g-busora.ads, g-busorg.adb, g-busorg.ads, g-casuti.adb, g-casuti.ads, g-catiio.adb, g-catiio.ads, g-cgi.adb, g-cgi.ads, g-cgicoo.adb, g-cgicoo.ads, g-cgideb.adb, g-cgideb.ads, g-comlin.adb, g-comlin.ads, g-crc32.adb, g-crc32.ads, g-debpoo.adb, g-debpoo.ads, g-debuti.adb, g-debuti.ads, g-diopit.adb, g-diopit.ads, g-dirope.adb, g-dirope.ads, g-dyntab.adb, g-dyntab.ads, g-except.ads, g-exctra.adb, g-exctra.ads, g-expect.adb, g-expect.ads, g-hesora.adb, g-hesora.ads, g-hesorg.adb, g-hesorg.ads, g-htable.adb, g-htable.ads, gigi.h, g-io.adb, g-io.ads, g-io_aux.adb, g-io_aux.ads, g-locfil.adb, g-locfil.ads, g-md5.adb, g-md5.ads, gmem.c, gnat1drv.adb, gnatbind.adb, gnatchop.adb, gnatcmd.adb, gnatfind.adb, gnatkr.adb, gnatlbr.adb, gnatlink.adb, gnatls.adb, gnatmake.adb, gnatmem.adb, gnatname.adb, gnatprep.adb, gnatprep.ads, gnatpsta.adb, gnatxref.adb, g-os_lib.adb, g-os_lib.ads, g-regexp.adb, g-regexp.ads, g-regist.adb, g-regist.ads, g-regpat.adb, g-regpat.ads, g-soccon.ads, g-socket.adb, g-socket.ads, g-socthi.adb, g-socthi.ads, g-soliop.ads, g-souinf.ads, g-speche.adb, g-speche.ads, g-spipat.adb, g-spipat.ads, g-spitbo.adb, g-spitbo.ads, g-sptabo.ads, g-sptain.ads, g-sptavs.ads, g-table.adb, g-table.ads, g-tasloc.adb, g-tasloc.ads, g-thread.adb, g-thread.ads, g-traceb.adb, g-traceb.ads, g-trasym.adb, g-trasym.ads, hostparm.ads, i-c.ads, i-cobol.adb, i-cpp.adb, i-cstrea.ads, i-cstrin.adb, i-cstrin.ads, impunit.adb, init.c, inline.adb, interfac.ads, i-pacdec.ads, itypes.adb, itypes.ads, i-vxwork.ads, lang.opt, lang-specs.h, layout.adb, lib.adb, lib.ads, lib-list.adb, lib-load.adb, lib-load.ads, lib-sort.adb, lib-util.adb, lib-writ.adb, lib-writ.ads, lib-xref.adb, lib-xref.ads, link.c, live.adb, make.adb, make.ads, Makefile.adalib, Makefile.in, Make-lang.in, makeusg.adb, mdll.adb, mdll-fil.adb, mdll-fil.ads, mdll-utl.adb, mdll-utl.ads, memroot.adb, memroot.ads, memtrack.adb, misc.c, mkdir.c, mlib.adb, mlib.ads, mlib-fil.adb, mlib-fil.ads, mlib-prj.adb, mlib-prj.ads, mlib-tgt.adb, mlib-tgt.ads, mlib-utl.adb, mlib-utl.ads, namet.adb, namet.ads, namet.h, nlists.ads, nlists.h, nmake.adt, opt.adb, opt.ads, osint.adb, osint.ads, osint-b.adb, osint-c.adb, par.adb, par-ch10.adb, par-ch11.adb, par-ch2.adb, par-ch3.adb, par-ch4.adb, par-ch5.adb, par-ch6.adb, par-ch9.adb, par-endh.adb, par-labl.adb, par-load.adb, par-prag.adb, par-sync.adb, par-tchk.adb, par-util.adb, prj.adb, prj.ads, prj-attr.adb, prj-attr.ads, prj-com.adb, prj-com.ads, prj-dect.adb, prj-dect.ads, prj-env.adb, prj-env.ads, prj-ext.adb, prj-ext.ads, prj-makr.adb, prj-makr.ads, prj-nmsc.adb, prj-nmsc.ads, prj-pars.adb, prj-pars.ads, prj-part.adb, prj-part.ads, prj-pp.adb, prj-pp.ads, prj-proc.adb, prj-proc.ads, prj-strt.adb, prj-strt.ads, prj-tree.adb, prj-tree.ads, prj-util.adb, prj-util.ads, raise.c, raise.h, repinfo.adb, repinfo.h, restrict.adb, restrict.ads, rident.ads, rtsfind.adb, rtsfind.ads, s-addima.ads, s-arit64.adb, s-assert.adb, s-assert.ads, s-atacco.adb, s-atacco.ads, s-auxdec.adb, s-auxdec.ads, s-bitops.adb, scans.ads, scn.adb, scn.ads, s-crc32.adb, s-crc32.ads, s-direio.adb, sem.adb, sem.ads, sem_aggr.adb, sem_attr.adb, sem_attr.ads, sem_case.adb, sem_case.ads, sem_cat.adb, sem_cat.ads, sem_ch10.adb, sem_ch11.adb, sem_ch12.adb, sem_ch12.ads, sem_ch13.adb, sem_ch13.ads, sem_ch3.adb, sem_ch3.ads, sem_ch4.adb, sem_ch5.adb, sem_ch5.ads, sem_ch6.adb, sem_ch6.ads, sem_ch7.adb, sem_ch7.ads, sem_ch8.adb, sem_ch8.ads, sem_ch9.adb, sem_disp.adb, sem_disp.ads, sem_dist.adb, sem_elab.adb, sem_eval.adb, sem_eval.ads, sem_intr.adb, sem_maps.adb, sem_mech.adb, sem_prag.adb, sem_prag.ads, sem_res.adb, sem_res.ads, sem_type.adb, sem_type.ads, sem_util.adb, sem_util.ads, sem_warn.adb, s-errrep.adb, s-errrep.ads, s-exctab.adb, s-exctab.ads, s-exnint.ads, s-exnllf.ads, s-exnlli.ads, s-expint.ads, s-explli.ads, s-expuns.ads, s-fatflt.ads, s-fatgen.adb, s-fatgen.ads, s-fatlfl.ads, s-fatllf.ads, s-fatsfl.ads, s-fileio.adb, s-fileio.ads, s-finimp.adb, s-finimp.ads, s-finroo.adb, s-finroo.ads, sfn_scan.adb, s-gloloc.adb, s-gloloc.ads, s-imgdec.adb, s-imgenu.adb, s-imgrea.adb, s-imgwch.adb, sinfo.adb, sinfo.ads, s-inmaop.ads, sinput.adb, sinput.ads, sinput-d.adb, sinput-l.adb, sinput-l.ads, sinput-p.adb, sinput-p.ads, s-interr.adb, s-interr.ads, s-intman.ads, s-maccod.ads, s-mastop.adb, s-mastop.ads, s-memory.adb, s-memory.ads, snames.adb, snames.ads, snames.h, s-osprim.ads, s-parame.ads, s-parint.ads, s-pooloc.adb, s-pooloc.ads, s-poosiz.adb, sprint.adb, s-proinf.ads, s-scaval.ads, s-secsta.adb, s-secsta.ads, s-sequio.adb, s-shasto.adb, s-shasto.ads, s-soflin.ads, s-stache.adb, s-stache.ads, s-stalib.adb, s-stalib.ads, s-stoele.ads, s-stopoo.ads, s-stratt.adb, s-stratt.ads, s-strops.adb, s-strops.ads, s-taasde.adb, s-taasde.ads, s-tadeca.adb, s-tadeca.ads, s-tadert.adb, s-tadert.ads, s-taenca.adb, s-taenca.ads, s-taprob.adb, s-taprob.ads, s-taprop.ads, s-tarest.adb, s-tarest.ads, s-tasdeb.adb, s-tasdeb.ads, s-tasinf.adb, s-tasinf.ads, s-tasini.adb, s-tasini.ads, s-taskin.adb, s-taskin.ads, s-tasque.adb, s-tasque.ads, s-tasren.adb, s-tasren.ads, s-tasres.ads, s-tassta.adb, s-tassta.ads, s-tasuti.adb, s-tasuti.ads, s-tataat.adb, s-tataat.ads, s-tpinop.adb, s-tpinop.ads, s-tpoben.adb, s-tpoben.ads, s-tpobop.adb, s-tpobop.ads, s-tposen.adb, s-tposen.ads, s-traceb.adb, s-traceb.ads, stringt.adb, stringt.ads, stringt.h, style.ads, stylesw.adb, stylesw.ads, s-unstyp.ads, s-vaflop.ads, s-valrea.adb, s-valuti.adb, s-vercon.adb, s-vmexta.adb, s-wchcnv.ads, s-wchcon.ads, s-widcha.adb, switch.adb, switch.ads, switch-b.adb, switch-c.adb, switch-m.adb, s-wwdcha.adb, s-wwdwch.adb, sysdep.c, system.ads, table.adb, table.ads, targparm.adb, targparm.ads, targtyps.c, tbuild.adb, tbuild.ads, tracebak.c, trans.c, tree_io.adb, treepr.adb, treeprs.adt, ttypes.ads, types.ads, types.h, uintp.adb, uintp.ads, uintp.h, uname.adb, urealp.adb, urealp.ads, urealp.h, usage.adb, utils2.c, utils.c, validsw.adb, validsw.ads, widechar.adb, xeinfo.adb, xnmake.adb, xref_lib.adb, xref_lib.ads, xr_tabls.adb, xr_tabls.ads, xtreeprs.adb, xsnames.adb, einfo.h, sinfo.h, treeprs.ads, nmake.ads, nmake.adb, gnatvsn.ads: Merge with ACT tree. * gnatvsn.adb: Rewritten in a simpler and more efficient way. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@72751 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-tifiio.adb')
-rw-r--r--gcc/ada/a-tifiio.adb555
1 files changed, 545 insertions, 10 deletions
diff --git a/gcc/ada/a-tifiio.adb b/gcc/ada/a-tifiio.adb
index a1b3badd96b..52f8e706458 100644
--- a/gcc/ada/a-tifiio.adb
+++ b/gcc/ada/a-tifiio.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 1992-1999 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -31,19 +31,284 @@
-- --
------------------------------------------------------------------------------
+-- Fixed point I/O
+-- ---------------
+
+-- The following documents implementation details of the fixed point
+-- input/output routines in the GNAT run time. The first part describes
+-- general properties of fixed point types as defined by the Ada 95 standard,
+-- including the Information Systems Annex.
+
+-- Subsequently these are reduced to implementation constraints and the impact
+-- of these constraints on a few possible approaches to I/O are given.
+-- Based on this analysis, a specific implementation is selected for use in
+-- the GNAT run time. Finally, the chosen algorithm is analyzed numerically in
+-- order to provide user-level documentation on limits for range and precision
+-- of fixed point types as well as accuracy of input/output conversions.
+
+-- -------------------------------------------
+-- - General Properties of Fixed Point Types -
+-- -------------------------------------------
+
+-- Operations on fixed point values, other than input and output, are not
+-- important for the purposes of this document. Only the set of values that a
+-- fixed point type can represent and the input and output operations are
+-- significant.
+
+-- Values
+-- ------
+
+-- Set set of values of a fixed point type comprise the integral
+-- multiples of a number called the small of the type. The small can
+-- either be a power of ten, a power of two or (if the implementation
+-- allows) an arbitrary strictly positive real value.
+
+-- Implementations need to support fixed-point types with a precision
+-- of at least 24 bits, and (in order to comply with the Information
+-- Systems Annex) decimal types need to support at least digits 18.
+-- For the rest, however, no requirements exist for the minimal small
+-- and range that need to be supported.
+
+-- Operations
+-- ----------
+
+-- 'Image and 'Wide_Image (see RM 3.5(34))
+
+-- These attributes return a decimal real literal best approximating
+-- the value (rounded away from zero if halfway between) with a
+-- single leading character that is either a minus sign or a space,
+-- one or more digits before the decimal point (with no redundant
+-- leading zeros), a decimal point, and N digits after the decimal
+-- point. For a subtype S, the value of N is S'Aft, the smallest
+-- positive integer such that (10**N)*S'Delta is greater or equal to
+-- one, see RM 3.5.10(5).
+
+-- For an arbitrary small, this means large number arithmetic needs
+-- to be performed.
+
+-- Put (see RM A.10.9(22-26))
+
+-- The requirements for Put add no extra constraints over the image
+-- attributes, although it would be nice to be able to output more
+-- than S'Aft digits after the decimal point for values of subtype S.
+
+-- 'Value and 'Wide_Value attribute (RM 3.5(40-55))
+
+-- Since the input can be given in any base in the range 2..16,
+-- accurate conversion to a fixed point number may require
+-- arbitrary precision arithmetic if there is no limit on the
+-- magnitude of the small of the fixed point type.
+
+-- Get (see RM A.10.9(12-21))
+
+-- The requirements for Get are identical to those of the Value
+-- attribute.
+
+-- ------------------------------
+-- - Implementation Constraints -
+-- ------------------------------
+
+-- The requirements listed above for the input/output operations lead to
+-- significant complexity, if no constraints are put on supported smalls.
+
+-- Implementation Strategies
+-- -------------------------
+
+-- * Float arithmetic
+-- * Arbitrary-precision integer arithmetic
+-- * Fixed-precision integer arithmetic
+
+-- Although it seems convenient to convert fixed point numbers to floating-
+-- point and then print them, this leads to a number of restrictions.
+-- The first one is precision. The widest floating-point type generally
+-- available has 53 bits of mantissa. This means that Fine_Delta cannot
+-- be less than 2.0**(-53).
+
+-- In GNAT, Fine_Delta is 2.0**(-63), and Duration for example is a
+-- 64-bit type. It would still be possible to use multi-precision
+-- floating-point to perform calculations using longer mantissas,
+-- but this is a much harder approach.
+
+-- The base conversions needed for input and output of (non-decimal)
+-- fixed point types can be seen as pairs of integer multiplications
+-- and divisions.
+
+-- Arbitrary-precision integer arithmetic would be suitable for the job
+-- at hand, but has the draw-back that it is very heavy implementation-wise.
+-- Especially in embedded systems, where fixed point types are often used,
+-- it may not be desirable to require large amounts of storage and time
+-- for fixed I/O operations.
+
+-- Fixed-precision integer arithmetic has the advantage of simplicity and
+-- speed. For the most common fixed point types this would be a perfect
+-- solution. The downside however may be a too limited set of acceptable
+-- fixed point types.
+
+-- Extra Precision
+-- ---------------
+
+-- Using a scaled divide which truncates and returns a remainder R,
+-- another E trailing digits can be calculated by computing the value
+-- (R * (10.0**E)) / Z using another scaled divide. This procedure
+-- can be repeated to compute an arbitrary number of digits in linear
+-- time and storage. The last scaled divide should be rounded, with
+-- a possible carry propagating to the more significant digits, to
+-- ensure correct rounding of the unit in the last place.
+
+-- An extension of this technique is to limit the value of Q to 9 decimal
+-- digits, since 32-bit integers can be much more efficient than 64-bit
+-- integers to output.
+
+with Interfaces; use Interfaces;
+with System.Arith_64; use System.Arith_64;
+with System.Img_Real; use System.Img_Real;
+with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO.Float_Aux;
+with Ada.Text_IO.Generic_Aux;
package body Ada.Text_IO.Fixed_IO is
- -- Note: we use the floating-point I/O routines for input/output of
- -- ordinary fixed-point. This works fine for fixed-point declarations
- -- whose mantissa is no longer than the mantissa of Long_Long_Float,
- -- and we simply consider that we have only partial support for fixed-
- -- point types with larger mantissas (this situation will not arise on
- -- the x86, but it will rise on machines only supporting IEEE long).
+ -- Note: we still use the floating-point I/O routines for input of
+ -- ordinary fixed-point and output using exponent format. This will
+ -- result in inaccuracies for fixed point types with a small that is
+ -- not a power of two, and for types that require more precision than
+ -- is available in Long_Long_Float.
package Aux renames Ada.Text_IO.Float_Aux;
+ Extra_Layout_Space : constant Field := 5 + Num'Fore;
+ -- Extra space that may be needed for output of sign, decimal point,
+ -- exponent indication and mandatory decimals after and before the
+ -- decimal point. A string with length
+
+ -- Fore + Aft + Exp + Extra_Layout_Space
+
+ -- is always long enough for formatting any fixed point number.
+
+ -- Implementation of Put routines
+
+ -- The following section describes a specific implementation choice for
+ -- performing base conversions needed for output of values of a fixed
+ -- point type T with small T'Small. The goal is to be able to output
+ -- all values of types with a precision of 64 bits and a delta of at
+ -- least 2.0**(-63), as these are current GNAT limitations already.
+
+ -- The chosen algorithm uses fixed precision integer arithmetic for
+ -- reasons of simplicity and efficiency. It is important to understand
+ -- in what ways the most simple and accurate approach to fixed point I/O
+ -- is limiting, before considering more complicated schemes.
+
+ -- Without loss of generality assume T has a range (-2.0**63) * T'Small
+ -- .. (2.0**63 - 1) * T'Small, and is output with Aft digits after the
+ -- decimal point and T'Fore - 1 before. If T'Small is integer, or
+ -- 1.0 / T'Small is integer, let S = T'Small and E = 0. For other T'Small,
+ -- let S and E be integers such that S / 10**E best approximates T'Small
+ -- and S is in the range 10**17 .. 10**18 - 1. The extra decimal scaling
+ -- factor 10**E can be trivially handled during final output, by adjusting
+ -- the decimal point or exponent.
+
+ -- Convert a value X * S of type T to a 64-bit integer value Q equal
+ -- to 10.0**D * (X * S) rounded to the nearest integer.
+ -- This conversion is a scaled integer divide of the form
+
+ -- Q := (X * Y) / Z,
+
+ -- where all variables are 64-bit signed integers using 2's complement,
+ -- and both the multiplication and division are done using full
+ -- intermediate precision. The final decimal value to be output is
+
+ -- Q * 10**(E-D)
+
+ -- This value can be written to the output file or to the result string
+ -- according to the format described in RM A.3.10. The details of this
+ -- operation are omitted here.
+
+ -- A 64-bit value can contain all integers with 18 decimal digits, but
+ -- not all with 19 decimal digits. If the total number of requested output
+ -- digits (Fore - 1) + Aft is greater than 18, for purposes of the
+ -- conversion Aft is adjusted to 18 - (Fore - 1). In that case, or
+ -- when Fore > 19, trailing zeros can complete the output after writing
+ -- the first 18 significant digits, or the technique described in the
+ -- next section can be used.
+
+ -- The final expression for D is
+
+ -- D := Integer'Max (-18, Integer'Min (Aft, 18 - (Fore - 1)));
+
+ -- For Y and Z the following expressions can be derived:
+
+ -- Q / (10.0**D) = X * S
+
+ -- Q = X * S * (10.0**D) = (X * Y) / Z
+
+ -- S * 10.0**D = Y / Z;
+
+ -- If S is an integer greater than or equal to one, then Fore must be at
+ -- least 20 in order to print T'First, which is at most -2.0**63.
+ -- This means D < 0, so use
+
+ -- (1) Y = -S and Z = -10**(-D).
+
+ -- If 1.0 / S is an integer greater than one, use
+
+ -- (2) Y = -10**D and Z = -(1.0 / S), for D >= 0
+
+ -- or
+
+ -- (3) Y = 1 and Z = (1.0 / S) * 10**(-D), for D < 0
+
+ -- Negative values are used for nominator Y and denominator Z, so that S
+ -- can have a maximum value of 2.0**63 and a minimum of 2.0**(-63).
+ -- For Z in -1 .. -9, Fore will still be 20, and D will be negative, as
+ -- (-2.0**63) / -9 is greater than 10**18. In these cases there is room
+ -- in the denominator for the extra decimal scaling required, so case (3)
+ -- will not overflow.
+
+ pragma Assert (System.Fine_Delta >= 2.0**(-63));
+ pragma Assert (Num'Small in 2.0**(-63) .. 2.0**63);
+ pragma Assert (Num'Fore <= 37);
+ -- These assertions need to be relaxed to allow for a Small of
+ -- 2.0**(-64) at least, since there is an ACATS test for this ???
+
+ Max_Digits : constant := 18;
+ -- Maximum number of decimal digits that can be represented in a
+ -- 64-bit signed number, see above
+
+ -- The constants E0 .. E5 implement a binary search for the appropriate
+ -- power of ten to scale the small so that it has one digit before the
+ -- decimal point.
+
+ subtype Int is Integer;
+ E0 : constant Int := -20 * Boolean'Pos (Num'Small >= 1.0E1);
+ E1 : constant Int := E0 + 10 * Boolean'Pos (Num'Small * 10.0**E0 < 1.0E-10);
+ E2 : constant Int := E1 + 5 * Boolean'Pos (Num'Small * 10.0**E1 < 1.0E-5);
+ E3 : constant Int := E2 + 3 * Boolean'Pos (Num'Small * 10.0**E2 < 1.0E-3);
+ E4 : constant Int := E3 + 2 * Boolean'Pos (Num'Small * 10.0**E3 < 1.0E-1);
+ E5 : constant Int := E4 + 1 * Boolean'Pos (Num'Small * 10.0**E4 < 1.0E-0);
+
+ Scale : constant Integer := E5;
+
+ pragma Assert (Num'Small * 10.0**Scale >= 1.0
+ and then Num'Small * 10.0**Scale < 10.0);
+
+ Exact : constant Boolean :=
+ Float'Floor (Num'Small) = Float'Ceiling (Num'Small)
+ or Float'Floor (1.0 / Num'Small) = Float'Ceiling (1.0 / Num'Small)
+ or Num'Small >= 10.0**Max_Digits;
+ -- True iff a numerator and denominator can be calculated such that
+ -- their ratio exactly represents the small of Num
+
+ -- Local Subprograms
+
+ procedure Put
+ (To : out String;
+ Last : out Natural;
+ Item : Num;
+ Fore : Field;
+ Aft : Field;
+ Exp : Field);
+ -- Actual output function, used internally by all other Put routines
+
---------
-- Get --
---------
@@ -100,8 +365,11 @@ package body Ada.Text_IO.Fixed_IO is
Aft : in Field := Default_Aft;
Exp : in Field := Default_Exp)
is
+ S : String (1 .. Fore + Aft + Exp + Extra_Layout_Space);
+ Last : Natural;
begin
- Aux.Put (File, Long_Long_Float (Item), Fore, Aft, Exp);
+ Put (S, Last, Item, Fore, Aft, Exp);
+ Generic_Aux.Put_Item (File, S (1 .. Last));
end Put;
procedure Put
@@ -110,8 +378,11 @@ package body Ada.Text_IO.Fixed_IO is
Aft : in Field := Default_Aft;
Exp : in Field := Default_Exp)
is
+ S : String (1 .. Fore + Aft + Exp + Extra_Layout_Space);
+ Last : Natural;
begin
- Aux.Put (Current_Out, Long_Long_Float (Item), Fore, Aft, Exp);
+ Put (S, Last, Item, Fore, Aft, Exp);
+ Generic_Aux.Put_Item (Text_IO.Current_Out, S (1 .. Last));
end Put;
procedure Put
@@ -120,8 +391,272 @@ package body Ada.Text_IO.Fixed_IO is
Aft : in Field := Default_Aft;
Exp : in Field := Default_Exp)
is
+ Fore : constant Integer := To'Length
+ - 1 -- Decimal point
+ - Field'Max (1, Aft) -- Decimal part
+ - Boolean'Pos (Exp /= 0) -- Exponent indicator
+ - Exp; -- Exponent
+ Last : Natural;
+
begin
- Aux.Puts (To, Long_Long_Float (Item), Aft, Exp);
+ if Fore not in Field'Range then
+ raise Layout_Error;
+ end if;
+
+ Put (To, Last, Item, Fore, Aft, Exp);
+
+ if Last /= To'Last then
+ raise Layout_Error;
+ end if;
+ end Put;
+
+ procedure Put
+ (To : out String;
+ Last : out Natural;
+ Item : Num;
+ Fore : Field;
+ Aft : Field;
+ Exp : Field)
+ is
+ subtype Digit is Int64 range 0 .. 9;
+ X : constant Int64 := Int64'Integer_Value (Item);
+ A : constant Field := Field'Max (Aft, 1);
+ Neg : constant Boolean := (Item < 0.0);
+ Pos : Integer; -- Next digit X has value X * 10.0**Pos;
+
+ Y, Z : Int64;
+ E : constant Integer := Boolean'Pos (not Exact)
+ * (Max_Digits - 1 + Scale);
+ D : constant Integer := Boolean'Pos (Exact)
+ * Integer'Min (A, Max_Digits - (Num'Fore - 1))
+ + Boolean'Pos (not Exact)
+ * (Scale - 1);
+
+
+ procedure Put_Character (C : Character);
+ pragma Inline (Put_Character);
+ -- Add C to the output string To, updating Last
+
+ procedure Put_Digit (X : Digit);
+ -- Add digit X to the output string (going from left to right),
+ -- updating Last and Pos, and inserting the sign, leading zeroes
+ -- or a decimal point when necessary. After outputting the first
+ -- digit, Pos must not be changed outside Put_Digit anymore
+
+ procedure Put_Int64 (X : Int64; Scale : Integer);
+ -- Output the decimal number X * 10**Scale
+
+ procedure Put_Scaled
+ (X, Y, Z : Int64;
+ A : Field;
+ E : Integer);
+ -- Output the decimal number (X * Y / Z) * 10**E, producing A digits
+ -- after the decimal point and rounding the final digit. The value
+ -- X * Y / Z is computed with full precision, but must be in the
+ -- range of Int64.
+
+ -------------------
+ -- Put_Character --
+ -------------------
+
+ procedure Put_Character (C : Character) is
+ begin
+ Last := Last + 1;
+ To (Last) := C;
+ end Put_Character;
+
+ ---------------
+ -- Put_Digit --
+ ---------------
+
+ procedure Put_Digit (X : Digit) is
+ Digs : constant array (Digit) of Character := "0123456789";
+ begin
+ if Last = 0 then
+ if X /= 0 or Pos <= 0 then
+ -- Before outputting first digit, include leading space,
+ -- posible minus sign and, if the first digit is fractional,
+ -- decimal seperator and leading zeros.
+
+ -- The Fore part has Pos + 1 + Boolean'Pos (Neg) characters,
+ -- if Pos >= 0 and otherwise has a single zero digit plus minus
+ -- sign if negative. Add leading space if necessary.
+
+ for J in Integer'Max (0, Pos) + 2 + Boolean'Pos (Neg) .. Fore
+ loop
+ Put_Character (' ');
+ end loop;
+
+ -- Output minus sign, if number is negative
+
+ if Neg then
+ Put_Character ('-');
+ end if;
+
+ -- If starting with fractional digit, output leading zeros
+
+ if Pos < 0 then
+ Put_Character ('0');
+ Put_Character ('.');
+
+ for J in Pos .. -2 loop
+ Put_Character ('0');
+ end loop;
+ end if;
+
+ Put_Character (Digs (X));
+ end if;
+
+ else
+ -- This is not the first digit to be output, so the only
+ -- special handling is that for the decimal point
+
+ if Pos = -1 then
+ Put_Character ('.');
+ end if;
+
+ Put_Character (Digs (X));
+ end if;
+
+ Pos := Pos - 1;
+ end Put_Digit;
+
+ ---------------
+ -- Put_Int64 --
+ ---------------
+
+ procedure Put_Int64 (X : Int64; Scale : Integer) is
+ begin
+ if X = 0 then
+ return;
+ end if;
+
+ Pos := Scale;
+
+ if X not in -9 .. 9 then
+ Put_Int64 (X / 10, Scale + 1);
+ end if;
+
+ Put_Digit (abs (X rem 10));
+ end Put_Int64;
+
+ ----------------
+ -- Put_Scaled --
+ ----------------
+
+ procedure Put_Scaled
+ (X, Y, Z : Int64;
+ A : Field;
+ E : Integer)
+ is
+ N : constant Natural := (A + Max_Digits - 1) / Max_Digits + 1;
+ pragma Debug (Put_Line ("N =" & N'Img));
+ Q : array (1 .. N) of Int64 := (others => 0);
+
+ XX : Int64 := X;
+ YY : Int64 := Y;
+ AA : Field := A;
+
+ begin
+ for J in Q'Range loop
+ exit when XX = 0;
+
+ Scaled_Divide (XX, YY, Z, Q (J), XX, Round => AA = 0);
+
+ -- As the last block of digits is rounded, a carry may have to
+ -- be propagated to the more significant digits. Since the last
+ -- block may have less than Max_Digits, the test for this block
+ -- is specialized.
+
+ -- The absolute value of the left-most digit block may equal
+ -- 10*Max_Digits, as no carry can be propagated from there.
+ -- The final output routines need to be prepared to handle
+ -- this specific case.
+
+ if (Q (J) = YY or -Q (J) = YY) and then J > Q'First then
+ if Q (J) < 0 then
+ Q (J - 1) := Q (J - 1) + 1;
+ else
+ Q (J - 1) := Q (J - 1) - 1;
+ end if;
+
+ Q (J) := 0;
+
+ Propagate_Carry :
+ for J in reverse Q'First + 1 .. Q'Last loop
+ if Q (J) >= 10**Max_Digits then
+ Q (J - 1) := Q (J - 1) + 1;
+ Q (J) := Q (J) - 10**Max_Digits;
+
+ elsif Q (J) <= -10**Max_Digits then
+ Q (J - 1) := Q (J - 1) - 1;
+ Q (J) := Q (J) + 10**Max_Digits;
+ end if;
+ end loop Propagate_Carry;
+ end if;
+
+ YY := -10**Integer'Min (Max_Digits, AA);
+ AA := AA - Integer'Min (Max_Digits, AA);
+ end loop;
+
+ for J in Q'First .. Q'Last - 1 loop
+ Put_Int64 (Q (J), E - (J - Q'First) * Max_Digits);
+ end loop;
+
+ Put_Int64 (Q (Q'Last), E - A);
+ end Put_Scaled;
+
+ -- Start of processing for Put
+
+ begin
+ Last := To'First - 1;
+
+ if Exp /= 0 then
+
+ -- With the Exp format, it is not known how many output digits to
+ -- generate, as leading zeros must be ignored. Computing too many
+ -- digits and then truncating the output will not give the closest
+ -- output, it is necessary to round at the correct digit.
+
+ -- The general approach is as follows: as long as no digits have
+ -- been generated, compute the Aft next digits (without rounding).
+ -- Once a non-zero digit is generated, determine the exact number
+ -- of digits remaining and compute them with rounding.
+ -- Since a large number of iterations might be necessary in case
+ -- of Aft = 1, the following optimization would be desirable.
+ -- Count the number Z of leading zero bits in the integer
+ -- representation of X, and start with producing
+ -- Aft + Z * 1000 / 3322 digits in the first scaled division.
+
+ -- However, the floating-point routines are still used now ???
+
+ System.Img_Real.Set_Image_Real (Long_Long_Float (Item), To, Last,
+ Fore, Aft, Exp);
+ return;
+ end if;
+
+ if Exact then
+ Y := Int64'Min (Int64 (-Num'Small), -1) * 10**Integer'Max (0, D);
+ Z := Int64'Min (Int64 (-1.0 / Num'Small), -1)
+ * 10**Integer'Max (0, -D);
+ else
+ Y := Int64 (-Num'Small * 10.0**E);
+ Z := -10**Max_Digits;
+ end if;
+
+ Put_Scaled (X, Y, Z, A - D, -D);
+
+ -- If only zero digits encountered, unit digit has not been output yet
+
+ if Last < To'First then
+ Pos := 0;
+ end if;
+
+ -- Always output digits up to the first one after the decimal point
+
+ while Pos >= -A loop
+ Put_Digit (0);
+ end loop;
end Put;
end Ada.Text_IO.Fixed_IO;