Sponsored Content
Top Forums Shell Programming and Scripting Q: Is SQRT(n) possible in a POSIX compliant shell? A: Yes within limits. Post 303039666 by wisecracker on Friday 11th of October 2019 10:51:01 AM
Old 10-11-2019
;oDD

I showed it to the wife and I said 'what sticks out the most?'
She said the 'pink obviously!'

Anyhow here is an add-on to get Fixed Point Numbers SQRT from .100 to 9200000.000 using 'sqrt_bash.sh' edited to 32 bit mode.
All entries MUST be Fixed Point values even if they end in ?.000...
Code:
#!/usr/local/bin/dash
# FP_sqrt.sh
#
# Requires sqrt_dash.sh to work.
# This MUST be 3 decimal places only using 'sqrt_bash.sh' in 32 bit mode running in 64 bit.
#
# Usage: [full/path/to/][./]FP_sqrt.sh <.100_to_a_little_over_9200000.000>
#
# Note: numbers below 1.000 the input must be .??? format without the leading zero.
# The errors below .100 grow exponentially so values cannot to be trusted.

NUMBER=${1}

# Step 1, allocate this to _fractional_ part.
FRACT="${NUMBER##*.}"

# Step 2, get _whole_number_ part.
WHOLE="${NUMBER%%.*}"

# Step 3, put WHOLE and FRACT together and include 3 zeros.
NUMBER="${WHOLE}${FRACT}"'000'

# Step 4, call "sqrt_dash.sh" with new NUMBER into a variable.
NUMBER=$( ./sqrt_dash.sh "${NUMBER}" )

printf "%.3f\n" ${NUMBER}e-3

Results, confirmed by Google. Same MBP platform as always.

Code:
Last login: Fri Oct 11 15:15:40 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh .100
0.316
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh .250
0.500
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh .500
0.707
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh .750
0.866
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh 1.000
1.000
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh 2.000
1.414
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh 20.000
4.472
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh 200.000
14.142
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh 333.333
18.257
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh 777.777
27.889
AMIGA:amiga~/Desktop/Code/Shell> ./FP_sqrt.sh 9187233.598
3031.045
AMIGA:amiga~/Desktop/Code/Shell> _

 

10 More Discussions You Might Find Interesting

1. Programming

sqrt

Hi! when i'm trying to compile this lite example on my linux machine I'll get errors and i don't know why.. #include <stdio.h> #include <math.h> /* needed by sqrt() */ int main() { printf("%f", sqrt(10.0)); return (0); } this is the error: /tmp/cc33hNVHK.o: In function... (1 Reply)
Discussion started by: CreamHarry
1 Replies

2. Programming

Is gcc compliant with the C++ standards

Hello Friends, I am a newbie and have started using different compilers and tools to make myself familiar with their workings. I wanted to know that how compliant is gcc with the C++ standards. It is pretty obvious that no compiler is close to being completely compliant, but if there are some... (7 Replies)
Discussion started by: hthapar
7 Replies

3. UNIX for Dummies Questions & Answers

sqrt in bash

Hi, i have a the following script: #!/bin/bash a=3 b=9 let "c= b*a" let "d=sqrt $c " echo $d But when i execute the code, it gives me the an error saying: line 5: let: d=sqrt 27 : syntax error in expression (error token is "27 ") Can any body tell me what I'm doing wrong? (5 Replies)
Discussion started by: limadario
5 Replies

4. Shell Programming and Scripting

Logical expression in POSIX compliant Korn Shell

Hi, i want to check if a variable var1 is not a or b or c pseudo code: If NOT (var1 = a or var1 = b or var1 = c) then ... fi I want to use POSIX complaint Korn shell, and for string comparison For the following code, logical.sh #!/usr/bin/ksh var="j" echo "Var : $var" if ! { || ||... (12 Replies)
Discussion started by: ysrini
12 Replies

5. UNIX for Dummies Questions & Answers

Soft and hard limits for nproc value in /etc/security/limits.conf file (Linux )

OS version : RHEL 6.5 Below is an excerpt from /etc/security/limits.conf file for OS User named appusr in our server appusr soft nproc 2047 appusr hard nproc 16384 What will happen if appusr has already spawned 2047 processes and wants to spawn 2048th process ? I just want to know... (3 Replies)
Discussion started by: kraljic
3 Replies

6. Shell Programming and Scripting

Is Rule 7 of POSIX shell grammar rules written correctly?

The POSIX shell standard grammar rules are at Shell Command Language I am trying to understand Rule 7 and I don't. I think there may be some mistakes there. I am not complaining about the standard; rather, I am concerned that my perception is wrong, and I don't understand something important.... (3 Replies)
Discussion started by: Mark_Galeck
3 Replies

7. Shell Programming and Scripting

Pure POSIX shell scripting...

Hi all... This is more of a concensus question than help... As many of you know I am experimenting with the limitations of Pure POSIX shell scripting. Q: Is the directory /bin considered part of the Pure POSIX shell or must I stick entirely with the builtins only? The reason is I... (2 Replies)
Discussion started by: wisecracker
2 Replies

8. What is on Your Mind?

Popularity-Boost for the POSIX-Shell in the Era of Containerized Computing?

Not even thinking that POSIX-Shell is deprecated, but I like working with bash very much, because of it's increased comfort and advanced functions. And in my world here it's available everywhere as default. Working with kubernetes now, it seems there is a paradigm shift in terms of resources.... (1 Reply)
Discussion started by: stomp
1 Replies

9. Shell Programming and Scripting

Equivalent to let command in POSIX shell

Hi all, I am learning POSIX shell programming, and the book I read, uses the let command for integer arithmetic. I have downloaded and use the shellcheck program on Linux. This programs says: In POSIX sh, 'let' is undefined. See the screenshot attached. What is the POSIX... (1 Reply)
Discussion started by: johnprogrammer
1 Replies

10. OS X (Apple)

Generate a random number in a fully POSIX compliant shell, 'dash'...

Hi all... Apologies for any typos, etc... This took a while but it didn't beat me... Although there are many methods of generating random numbers in a POSIX shell this uses integer maths and a simple C source to create an executable to get epoch to microseconds accuracy if it is needed. I take... (8 Replies)
Discussion started by: wisecracker
8 Replies
Desktop::Notify::Notification(3pm)			User Contributed Perl Documentation			Desktop::Notify::Notification(3pm)

NAME
Desktop::Notify::Notification - a notification object for the desktop notifications framework VERSION
Version 0.03 SYNOPSIS
# $notify is an existing Desktop::Notify object my $note = $notify->create(summary => 'Rebuilding FooBar', body => 'Progress: 10%'); $note->show; ... # Update the notification later $note->body('Progress: 20%'); $note->show; ... # Take it off the screen $note->close; DESCRIPTION
Desktop notification objects are represented as objects of this class. They are created by a Desktop::Notify object. Displaying, closing, and modifying the notification is done by using methods in this class. METHODS
new $notify, %params This is called internally by Desktop::Notify to create a new notification object. show Display the notification on the screen. If this notification had previously been shown and not closed yet, it will replace the existing notification. Show can be called multiple times on the same notification, probably with attribute changes between calls, and later show calls will cause the server to seamlessly replace the existing notification. close Close the notification if it is already being displayed. ATTRIBUTES
The following parameters can be set when creating the object or later modified using accessors (descriptions are from the specification at <http://www.galago-project.org/specs/notification/0.9/x408.html>) summary The summary text briefly describing the notification. body The optional detailed body text. Can be empty. timeout The timeout time in milliseconds since the display of the notification at which the notification should automatically close. If -1, the notification's expiration time is dependent on the notification server's settings, and may vary for the type of notification. If 0, never expire. The following extra parameters are included in the specification but not supported by Desktop::Notify at this time app_icon The optional program icon of the calling application. actions Actions are sent over as a list of pairs. Each even element in the list (starting at index 0) represents the identifier for the action. Each odd element in the list is the localized string that will be displayed to the user. hints Optional hints that can be passed to the server from the client program. perl v5.10.1 2009-12-25 Desktop::Notify::Notification(3pm)
All times are GMT -4. The time now is 06:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy