bc

Arithmetic with floating point

眉间皱痕 提交于 2020-07-22 21:41:01
问题 I have a very simple problem, i'm making a function that receives some floating point numbers and make a couple of operations with them at the beggining. Something like this: function x { A=$1 B=$2 # here i need a ratio, so i do, let's say.. sum=$(($A + $B)) C=$(($A / $sum)) [lots of code here] } The problem is that $1 and $2 are floating point numbers, or even if they're ints, the ratio it's very likely not to be an int, so i don't know how to operate them under bash. I tried with a bc pipe

Arithmetic with floating point

北城余情 提交于 2020-07-22 21:38:19
问题 I have a very simple problem, i'm making a function that receives some floating point numbers and make a couple of operations with them at the beggining. Something like this: function x { A=$1 B=$2 # here i need a ratio, so i do, let's say.. sum=$(($A + $B)) C=$(($A / $sum)) [lots of code here] } The problem is that $1 and $2 are floating point numbers, or even if they're ints, the ratio it's very likely not to be an int, so i don't know how to operate them under bash. I tried with a bc pipe

Oracle与PostgreSQL中Timestamp型公元前、后数值的详解及JDBC存取

橙三吉。 提交于 2020-04-25 18:27:28
字段:date value1: 2010-01-01 value2: 2010-01-01BC 1.直接向数据库插入数值时: oracle需要使用to_timestamp('2010-01-01','yyyy-mm-ddBC'), PG可以直接用字符串‘2010-01-01BC'。 2.直接从数据库查询时: 在oracle数据库中直接查询date字段,value1和value1显示没有区别,均为2010-01-01, 使用to_char(time,'dd-mm-yyyybc','nls_date_language=American') ,才显示出bc和ad。如下: SQL> select time,to_char(time,'dd-mm-yyyybc','nls_date_language=American') AS TRUDATE; TIME TRUEDATE --------------------------------------------------------------------------- 01-JAN-10 12.00.00.000000 AM 01-01-2010bc 01-JAN-10 12.00.00.000000 AM 01-01-2010ad 在PG中:直接查询即可显示BC,如下: highgo=# select * from testtime;

Bash Scripting and bc

旧时模样 提交于 2020-01-22 17:43:07
问题 I'm trying to write a bash script and I needed to do some floating point math. Basically I want to do something like this: NUM=$(echo "scale=25;$1/10" | bc) if [ $? -ne 0 ] then echo bad fi The problem I'm running into is $? tends to hold the output from the echo program and not the bc call. Is there a way I save the output from the bc program into a variable? EDIT: Thanks for the quick replies. Here's another way of looking at the problem. Say I modified the script a little bit so it looks

Why querying a date BC is changed to AD in Java?

荒凉一梦 提交于 2019-12-24 02:23:36
问题 My program in Java connects to a Database (Oracle XE 11g) which contains many dates (date format of OracleXE is set to syyyy/mm/dd). Doing a query in the database with negative dates (before Christ) works fine. When I do it in Java, they are all changed to AD (Anno Domini). How can I retrieve dates in Java respecting AD/BC? My Java code here does the query to the DB and puts the result in a table. try { Object item=cbPD.getSelectedItem(); String dacercare=item.toString(); query = "SELECT

Why querying a date BC is changed to AD in Java?

℡╲_俬逩灬. 提交于 2019-12-24 02:23:24
问题 My program in Java connects to a Database (Oracle XE 11g) which contains many dates (date format of OracleXE is set to syyyy/mm/dd). Doing a query in the database with negative dates (before Christ) works fine. When I do it in Java, they are all changed to AD (Anno Domini). How can I retrieve dates in Java respecting AD/BC? My Java code here does the query to the DB and puts the result in a table. try { Object item=cbPD.getSelectedItem(); String dacercare=item.toString(); query = "SELECT

Subtract corresponding lines

大憨熊 提交于 2019-12-24 02:06:27
问题 I have two files, file1.csv 3 1009 7 1012 2 1013 8 1014 and file2.csv 5 1009 3 1010 1 1013 In the shell, I want to subtract the count in the first column in the second file from that in the first file, based on the identifier in the second column. If an identifier is missing in the second column, the count is assumed to be 0. The result would be -2 1009 -3 1010 7 1012 1 1013 8 1014 The files are huge (several GB). The second columns are sorted. How would I do this efficiently in the shell?

awk output into BC HexToDec calculation

随声附和 提交于 2019-12-23 02:01:43
问题 I am trying to combine awk and bc in order to create a bash function for quickly converting hex values into a proper format. echo FFFFFF | VAR=$(awk '{print toupper($0)}') | "ibase=16; $((((($VAR - 5) / 100) - 1000)))" | bc I am trying this but I cant seem to get the output of awk into the input of the bc argument. 回答1: Although you try to do it with awk and bc , I give you the most convenient option here : printf . This allows you to easily convert between decimal, octal and hexadecimal.

Bash decimal to base 62 conversion

耗尽温柔 提交于 2019-12-22 03:50:45
问题 I would like to reverse the operation performed by the following bash command: $ echo $((62#a39qrT)) 9207903953 i.e. convert decimal 9207903953 to base 62 , keeping bash standard of {0..9},{a..z},{A..Z} . I know I can do this by using bc , but I will have to manually convert each character then. For example, I do this currently: BASE62=($(echo {0..9} {a..z} {A..Z})) for i in $(echo "obase=62; 9207903953" | bc) do echo -n ${BASE62[$i]} #Doesn't work if bc's output contains leading zeroes done

Hex to Binary conversion in bash

白昼怎懂夜的黑 提交于 2019-12-21 04:06:47
问题 I'm trying to convert a series of bytes from hex to bin using bash. but I keep getting (seemingly random) "(standard_in) 1: syntax error" replies from the following code: for j in c4 97 91 8c 85 87 c4 90 8c 8d 9a 83 81 do BIN=$(echo "obase=2; ibase=16; $j" | bc ) echo $BIN done I did a similar thing with dec to bin, which works perfectly fine: for i in {0..120} do KEYBIN=$(echo "obase=2; ibase=10; $i" | bc) echo $KEYBIN done Does anyone have an idea why it works with decimal, but not with hex