Sponsored Content
Top Forums Shell Programming and Scripting awk, floating point and rounding Post 302488947 by fpmurphy on Wednesday 19th of January 2011 12:09:44 AM
Old 01-19-2011
The "error" is due to the default rounding.
Code:
BEGIN   {
        for (i=5; i < 7; i+=1) {
                printf "Pass %s...\n",i
                for (j = 0.0; j < (0.1*i); j = j + 0.1) {
                        printf "j=%.20f %.20f\n", j, .1*i;
                }
        }
exit
}

Code:
Pass 5...
j=0.00000000000000000000 0.50000000000000000000
j=0.10000000000000000555 0.50000000000000000000
j=0.20000000000000001110 0.50000000000000000000
j=0.30000000000000004441 0.50000000000000000000
j=0.40000000000000002220 0.50000000000000000000
Pass 6...
j=0.00000000000000000000 0.60000000000000008882
j=0.10000000000000000555 0.60000000000000008882
j=0.20000000000000001110 0.60000000000000008882
j=0.30000000000000004441 0.60000000000000008882
j=0.40000000000000002220 0.60000000000000008882
j=0.50000000000000000000 0.60000000000000008882
j=0.59999999999999997780 0.60000000000000008882

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Floating Point Division

Does anyone have a simple way of doing floating point ("fp") division? For example, if I divide 3 by 5, I can get 0.6. The built-in calc (`bc`) will perform fp multiplication, but not division, at least not straight-up (i.e., starting bc and just typing in 3/5). I am trying to do this using... (1 Reply)
Discussion started by: gsatch
1 Replies

2. Shell Programming and Scripting

problem with floating point numbers in awk

hi all, i have the following problem using awk in a script i want to read the values from a column with real numbers and calculate the mean.the problem is that when i use a statement such as this num = $4 i cant find a way to convert the variable from string to floating point to perform... (7 Replies)
Discussion started by: kanagias
7 Replies

3. Shell Programming and Scripting

floating point addition

hi, :) I have a file like this 10.456 123.567 456.876 234.987 ........ ....... What i want to do is ia have to add all those numbers and put the result in some other file. Any help pls. cheers RRK (8 Replies)
Discussion started by: ravi raj kumar
8 Replies

4. Shell Programming and Scripting

Replace floating-point by integer in awk

Hi, I am trying to write a script to extract multiple sets of data from a chemistry output file. The problem section is in the following format... Geometry "geometry" -> "geometry" 1 Pd 46.0000 -0.19290971 0.00535260 0.02297606 2 P ... (7 Replies)
Discussion started by: smadonald1
7 Replies

5. Shell Programming and Scripting

Rounding off the value of Floating point value

Hello, i have some variables say: x=1.4 y=3.7 I wish to round off these values to : x = 2 (after rounding off) y = 4 (after rounding off) I am stuck. Please help. (7 Replies)
Discussion started by: damansingh
7 Replies

6. Linux

Floating Point Exception

Hi, I am compiling "HelloWorld" C progam on 32-bit CentOS and i want to execute it on 64-bit CentOS architecture. For that i copied the a.out file from 32-bit to 64-bit machine, but while executing a.out file on 64bit machine I am getting "Floating point exception error". But we can run... (3 Replies)
Discussion started by: Mandar123
3 Replies

7. Shell Programming and Scripting

how to compare 2 floating point no.

Hi, Could any one tell me how to compare to floating point no. using test command. As -eq option works on only intergers. i=5.4 if then echo "equal" else echo "not equal" fi here output will be equal even though no. are unequal. Thanks, ravi (1 Reply)
Discussion started by: useless79
1 Replies

8. Shell Programming and Scripting

Arithmetic in floating point

is it not possible to simply di aritmetic without using bc or awk i have tried folllowing operatrions but they support only integer types plz suggest me code for floating using values stored in the variables.the ans i get is integer and if i input floating values i get error numeric constant... (6 Replies)
Discussion started by: sumit the cool
6 Replies

9. Programming

Floating Point

Anyone help me i cant found the error of floating point if needed, i added the code complete #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> typedef struct { int hh; int mm; int ss; char nom; int punt; }cancion; typedef struct... (9 Replies)
Discussion started by: Slasho
9 Replies

10. Shell Programming and Scripting

Rounding off to the nearest floating number

I have a number, which I want to convert into the nearest floating number upto two places after the decimal point. E.g. 1.2346 will become 1.23 but 1.2356 will become 1.24 . Similarly 0.009 will be 0.01 and 0.001 will be 0.00 or 0.0 (not 0, wnat to keep the decimal... (1 Reply)
Discussion started by: hbar
1 Replies
xml2ag(1)							   User Commands							 xml2ag(1)

NAME
xml2ag - XML to AutoGen Definiton Converter SYNOPSIS
xml2ag [-flag [value]]... [--opt-name [[=| ]value]]...[<def-file>] This program will convert any arbitrary XML file into equivalent AutoGen definitions, and invoke AutoGen. DESCRIPTION
The template will be derived from either: * the --override-tpl command line option * a top level XML attribute named, "template" One or the other must be provided, or the program will exit with a failure message. The ``base-name'' for the output will similarly be either: * the --base-name command line option * the base name of the .xml file OPTIONS
-O file, --output=file Output file in lieu of AutoGen processing. By default, the output is handed to an AutoGen for processing. However, you may save the definitions to a file instead. -L dir, --templ-dirs=dir Template search directory list. This option may appear an unlimited number of times. Pass-through AutoGen argument -T tpl-file, --override-tpl=tpl-file Override template file. Pass-through AutoGen argument -l tpl-file, --lib-template=tpl-file Library template file. This option may appear an unlimited number of times. Pass-through AutoGen argument -b name, --base-name=name Base name for output file(s). Pass-through AutoGen argument --definitions=file Definitions input file. Pass-through AutoGen argument -S file, --load-scheme=file Scheme code file to load. Pass-through AutoGen argument -F file, --load-functions=file Load scheme function library. Pass-through AutoGen argument -s suffix, --skip-suffix=suffix Omit the file with this suffix. This option may appear an unlimited number of times. This option must not appear in combination with any of the following options: select-suffix. Pass-through AutoGen argument -o suffix, --select-suffix[=suffix] specify this output suffix. This option may appear an unlimited number of times. Pass-through AutoGen argument --source-time set mod times to latest source. Pass-through AutoGen argument -m, --no-fmemopen Do not use in-mem streams. Pass-through AutoGen argument --equate=char-list characters considered equivalent. Pass-through AutoGen argument --writable, --not-writable Allow output files to be writable. The not-writable form will disable the option. Pass-through AutoGen argument --loop-limit=lim Limit on increment loops. This option takes an integer number as its argument. The value of lim is constrained to being: exactly -1, or in the range 1 through 0x1000000 The default lim for this option is: 256 Pass-through AutoGen argument --shell=shell name or path name of shell to use. Pass-through AutoGen argument -t time-lim, --timeout=time-lim Time limit for server shell. This option takes an integer number as its argument. The value of time-lim is constrained to being: in the range 0 through 3600 Pass-through AutoGen argument --trace=level tracing level of detail. This option takes a keyword as its argument. The argument sets an enumeration value that can be tested by comparing them against the option value macro. The available keywords are: nothing debug-message server-shell templates block-macros expressions everything or their numeric equivalent. The default level for this option is: nothing Pass-through AutoGen argument --trace-out=file tracing output file or filter. Pass-through AutoGen argument --show-defs Show the definition tree. Pass-through AutoGen argument --used-defines Show the definitions used. Pass-through AutoGen argument -D value, --define=value name to add to definition list. This option may appear an unlimited number of times. Pass-through AutoGen argument -U name-pat, --undefine=name-pat definition list removal pattern. This option may appear an unlimited number of times. Pass-through AutoGen argument -M type, --make-dep[=type] emit make dependency file. This option may appear an unlimited number of times. Pass-through AutoGen argument -C, --core Leave a core dump on a failure exit. Many systems default to a zero sized core limit. If the system has the sys/resource.h header and if this option is supplied, then in the failure exit path, autogen will attempt to set the soft core limit to whatever the hard core limit is. If that does not work, then an administrator must raise the hard core size limit. -?, --help Display usage information and exit. -!, --more-help Pass the extended usage information through a pager. -v [{v|c|n}], --version[={v|c|n}] Output version of program and exit. The default mode is `v', a simple version. The `c' mode will print copyright information and `n' will print the full copyright notice. EXIT STATUS
One of the following exit values will be returned: 0 Successful program execution. 1 The command options were misconfigured. 2 An error was encountered processing the template. 3 The definitions could not be deciphered. 4 An error was encountered during the load phase. 5 Program exited due to catching a signal. If your template includes string formatting, a number argument to a "%s" formatting ele- ment will trigger a segmentation fault. Autogen will catch the seg fault signal and exit with code 5. AUTHORS
Bruce Korb COPYRIGHT
Copyright (C) 1992-2011 Bruce Korb all rights reserved. This program is released under the terms of the GNU General Public License, ver- sion 3 or later. BUGS
Please send bug reports to: autogen-users@lists.sourceforge.net NOTES
This manual page was AutoGen-erated from the xml2ag option definitions. GNU AutoGen (5.12) 10 Jul 2011 xml2ag(1)
All times are GMT -4. The time now is 04:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy