Sponsored Content
Operating Systems OS X (Apple) A Fun Perfect Square Checker Using Integer Arithmetic Only... ;o) Post 302952702 by wisecracker on Friday 21st of August 2015 04:16:54 AM
Old 08-21-2015
Fellas, fellas, settle down... ;oD

I seem to have created a riot on this thread; now let me mediate.

Firstly I did quote using "INTEGER arithmetic".

Secondly I also quoted "it is a little tongue-in-cheek".

And thirdly it uses builtins only...

At Don...
Don, in his defence, used builtins although not INTEGER arithmetic; he admitted that ksh93 was used as he expended on my original upload using ksh's floating point - root=$((int(number ** .5))) ; I am assuming 'int' is part of ksh's arithmetic...
So Don, as bash cannot do floating point then you did cheat... ;oD

At neutronscott...
Well what can I say... ;oD
Using various [?]awk commands are not builtins so you also cheated... ;oD

At sea...
It would have been interesting to see your result too...

One very serious question however:-

How accurate is either "[?]awk's" or "ksh's" floating point?
Would there be a situation where there would be a false result due to a floating point __error__?

Bazza...
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extraction of perfect text from file.

Hi All, I have a file of the following format. <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="manager"/> <role rolename="admin"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user... (5 Replies)
Discussion started by: nua7
5 Replies

2. UNIX for Dummies Questions & Answers

A perfect number shell program

Here's my work of testing whether a number input is perfect or not.. echo Enter a number read no i=1 ans=0 while do if then ans='expr $ans + $i' fi i='expr $i + 1' done if then echo $no is perfect else echo $no is NOT perfect fi (12 Replies)
Discussion started by: Cyansnow
12 Replies

3. AIX

I want the perfect user-interface

I've got an aix-box somewhere on the network and a PC on my desk. Nothing fancy so far. The PC is made dual-boot: - windowsXP with putty & winSCP or - slackware 13 with xfce4 installed. The aix-box runs DB2 v8.2 and I've installed db2top to monitor the database. db2top is a character... (0 Replies)
Discussion started by: dr_te_z
0 Replies

4. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

5. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

6. UNIX for Dummies Questions & Answers

Can you perfect my sed ?

I want to print only the lines that meet the criteria : "worde:" and "wordo;" I got this far: sed -n '/\(*\)\1e:\1o;/p;' But it doesn't quite work. Can someone please perfect it and tell me exactly how its a fixed version/what was wrong with mine? Thanks heaps, (1 Reply)
Discussion started by: maximus73
1 Replies

7. Shell Programming and Scripting

egrep line with perfect mach

Hi Input File A L006 AL01 0 (OCK) L006 A006 0 (OCK) L011 AR11 1 (NLOCK) Input File B L006 AL01 0 (OCK) L006 A006 0 (OCK) Need Egrep Command for perfect Match Thanks (4 Replies)
Discussion started by: asavaliya
4 Replies

8. Shell Programming and Scripting

Not able to find the perfect code...Geting confused in between

I have to find last delimiter in each line of a file and store the value after the last '/' in a variable in ksh script...Pls Pls help me:(The file is as shown below: /opt/apps/cobqa/apps/abadv/bind/advc0007.bnd /opt/apps/cobqa/apps/abbrio/bind/naac6115.bnd... (5 Replies)
Discussion started by: bhavanabahety
5 Replies
funparamget(3)							SAORD Documentation						    funparamget(3)

NAME
FunParamGet - get a Funtools param value SYNOPSIS
#include <funtools.h> int FunParamGetb(Fun fun, char *name, int n, int defval, int *got) int FunParamGeti(Fun fun, char *name, int n, int defval, int *got) double FunParamGetd(Fun fun, char *name, int n, double defval, int *got) char *FunParamGets(Fun fun, char *name, int n, char *defval, int *got) DESCRIPTION
The four routines FunParamGetb(), FunParamGeti(), FunParamGetd(), and FunParamGets(), return the value of a FITS header parameter as a boolean, int, double, and string, respectively. The string returned by FunParamGets() is a malloc'ed copy of the header value and should be freed when no longer needed. The first argument is the Fun handle associated with the FITS header being accessed. Normally, the header is associated with the FITS extension that you opened with FunOpen(). However, you can use FunInfoPut() to specify access of the primary header. In particular, if you set the FUN_PRIMARYHEADER parameter to 1, then the primary header is used for all parameter access until the value is reset to 0. For exam- ple: int val; FunParamGeti(fun, "NAXIS", 1, 0, &got); # current header val=1; FunInfoPut(fun, FUN_PRIMARYHEADER, &val, 0); # switch to ... FunParamGeti(fun, "NAXIS", 1, 0, &got); # ... primary header FunParamGeti(fun, "NAXIS", 2, 0, &got); # ... primary header val=0; FunInfoPut(fun, FUN_PRIMARYHEADER, &val, 0); # switch back to ... FunParamGeti(fun, "NAXIS", 2, 0, &got); # current header Alternatively, you can use the FUN_PRIMARY macro to access parameters from the primary header on a per-parameter basis: FunParamGeti(fun, "NAXIS1", 0, 0, &got); # current header FunParamGeti(FUN_PRIMARY(fun), "NAXIS1", 0, 0, &got); # primary header NB - FUN_PRIMARY is deprecated. It makes use of a global parameter and therefore will not not appropriate for threaded applications, when we make funtools thread-safe. We recommend use of FunInfoPut() to switch between the extension header and the primary header. For output data, access to the primary header is only possible until the header is written out, which usually takes place when the first data are written. The second argument is the name of the parameter to access. The third n argument, if non-zero, is an integer that will be added as a suf- fix to the parameter name. This makes it easy to use a simple loop to process parameters having the same root name. For example, to gather up all values of TLMIN and TLMAX for each column in a binary table, you can use: for(i=0, got=1; got; i++){ fun->cols[i]->tlmin = (int)FunParamGeti(fun, "TLMIN", i+1, 0.0, &got); fun->cols[i]->tlmax = (int)FunParamGeti(fun, "TLMAX", i+1, 0.0, &got); } The fourth defval argument is the default value to return if the parameter does not exist. Note that the data type of this parameter is different for each specific FunParamGet() call. The final got argument will be 0 if no param was found. Otherwise the data type of the parameter is returned as follows: FUN_PAR_UNKNOWN ('u'), FUN_PAR_COMMENT ('c'), FUN_PAR_LOGICAL ('l'), FUN_PAR_INTEGER ('i'), FUN_PAR_STRING ('s'), FUN_PAR_REAL ('r'), FUN_PAR_COMPLEX ('x'). These routines return the value of the header parameter, or the specified default value if the header parameter does not exist. The returned value is a malloc'ed string and should be freed when no longer needed. By default, FunParamGets() returns the string value of the named parameter. However, you can use FunInfoPut() to retrieve the raw 80-character FITS card instead. In particular, if you set the FUN_RAWPARAM parameter to 1, then card images will be returned by Fun- ParamGets() until the value is reset to 0. Alternatively, if the FUN_RAW macro is applied to the name, then the 80-character raw FITS card is returned instead. NB - FUN_RAW is deprecated. It makes use of a global parameter and therefore will not not appropriate for threaded applications, when we make funtools thread-safe. We recommend use of FunInfoPut() to switch between the extension header and the primary header. Note that in addition to the behaviors described above, the routine FunParamGets() will return the 80 raw characters of the nth FITS card (including the comment) if name is specified as NULL and n is positive. For example, to loop through all FITS header cards in a given extension and print out the raw card, use: for(i=1; ;i++){ if( (s = FunParamGets(fun, NULL, i, NULL, &got)) ){ fprintf(stdout, "%.80s ", s); free(s); } else{ break; } } SEE ALSO
See funtools(7) for a list of Funtools help pages version 1.4.2 January 2, 2008 funparamget(3)
All times are GMT -4. The time now is 09:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy