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
GAC(1)								   User Commands							    GAC(1)

NAME
GAC - The GAP Compiler SYNOPSIS
gac [-c|-d] [-o <output>] {-f<option>} <input>... DESCRIPTION
GAC compiles the input files. Input files must be GAP source code (suffix '.g' or '.gap'), C source code (suffix '.c'), or compiled code files (suffix '.o'). If neither -c nor -d is given, then 'gac' produces a new kernel, which contains the compiled code for all the input files. -c Compiles the input files to statically loadable object files, which must be linked together to a new kernel. -d Compiles the input files to dynamically loadable object files, which can be loaded by a kernel at runtime. -C Only compiles the input files to C code, which will require compilation and linking to be usable. -r Statically compiled files will be assumed to be given by pathnames relative to the GAP root, and will be compiled for automatic loading when files are sought relative to the GAP root. -o <output> Name the output file <output>. -ffast-int-arith Emit code for arithmetic operations, which works faster if both operands are small integers and slower otherwise. -ffast-plain-lists Emit code for list access, which works faster if the list is a plain list and slower otherwise. -ffast-list-funcs Inline the functions 'Add' and 'Length' the code, which makes it a bit faster. -fno-check-types Emit no error checks for list access, which makes it faster but may dump core if an error happens. -p <option> Pass the option <option> to the C compiler. -P <option> Pass the option <option> to the C linker. SEE ALSO
gap(1) You can read the complete manual in /usr/share/gap/doc or you can use the online help system. Type ?help inside GAP to access it. AUTHORS
The GAP Group <http://www.gap-system.org> COPYRIGHT
Copyright (1987--2006) by the GAP Group, GAP is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GAP team March 2003 GAC(1)
All times are GMT -4. The time now is 04:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy