From 133820dd1b17c0bf8eff446e5d93ba14366ed518 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 8 May 2021 21:08:12 +0000 Subject: lua-physical (8may21) git-svn-id: svn://tug.org/texlive/trunk@59138 c570f23f-e606-0410-a88d-b1316a301751 --- .../scripts/lua-physical/physical-astronomical.lua | 2 +- .../scripts/lua-physical/physical-data.lua | 2 +- .../scripts/lua-physical/physical-definition.lua | 8 +++- .../scripts/lua-physical/physical-dimension.lua | 2 +- .../scripts/lua-physical/physical-number.lua | 52 +++++++++++++++++----- .../scripts/lua-physical/physical-quantity.lua | 14 ++++-- .../scripts/lua-physical/physical-unit.lua | 2 +- .../texmf-dist/scripts/lua-physical/physical.lua | 4 +- 8 files changed, 64 insertions(+), 22 deletions(-) (limited to 'Master/texmf-dist/scripts') diff --git a/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua b/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua index 48ca5646b86..629832b8790 100644 --- a/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua +++ b/Master/texmf-dist/scripts/lua-physical/physical-astronomical.lua @@ -1,7 +1,7 @@ --[[ Astronomical data -Copyright (c) 2020 Thomas Jenni +Copyright (c) 2021 Thomas Jenni Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Master/texmf-dist/scripts/lua-physical/physical-data.lua b/Master/texmf-dist/scripts/lua-physical/physical-data.lua index efc1a30ffaf..f77eee9f8d9 100644 --- a/Master/texmf-dist/scripts/lua-physical/physical-data.lua +++ b/Master/texmf-dist/scripts/lua-physical/physical-data.lua @@ -1,7 +1,7 @@ --[[ This file contains the methods for accessing physical data. -Copyright (c) 2020 Thomas Jenni +Copyright (c) 2021 Thomas Jenni Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Master/texmf-dist/scripts/lua-physical/physical-definition.lua b/Master/texmf-dist/scripts/lua-physical/physical-definition.lua index cf1576b4c54..5e0ec79a73c 100644 --- a/Master/texmf-dist/scripts/lua-physical/physical-definition.lua +++ b/Master/texmf-dist/scripts/lua-physical/physical-definition.lua @@ -2,7 +2,7 @@ This file contains the definitions for dimensions, prefixes, SI, Imperial and U.S. Survey units -Copyright (c) 2020 Thomas Jenni +Copyright (c) 2021 Thomas Jenni Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -119,7 +119,7 @@ Q.definePrefix("Ki", "kibi", 1024) local IEC_prefixes = {"Ki","Mi","Gi","Ti","Pi","Ei","Zi","Yi"} -- define the dimensionless base quantity for real numbers -Q.define("1", "number", Q(1)) +Q.define("1", "unitless", Q(1)) -- define SI base units Q.defineBase("m", "meter", L) @@ -276,6 +276,8 @@ Q.define("t", "tonne", 1e3 * _kg) -- https://arxiv.org/pdf/1605.09788.pdf -- https://arxiv.org/pdf/1510.07674.pdf +Q.define("mag", "magnitude", _1) + Q.define("R_S_nom", "nomsolradius", 6.957e8 * _m) Q.define("S_S_nom", "nomsolirradiance", 1361 * _W/_m^2) Q.define("L_S_nom", "nomsolluminosity", 3.828e26 * _W) @@ -290,6 +292,8 @@ Q.define("Re_J_nom", "nomjoveqradius", 7.1492e7 * _m) Q.define("Rp_J_nom", "nomjovpolradius", 6.6854e7 * _m) Q.define("GM_J_nom", "nomjovmassparameter", 1.2668653e17 * _m^3*_s^-2) +Q.define("M_S", "solmass", N(1.98847e30,0.00007e30) * _kg) + diff --git a/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua b/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua index edd9e65997e..03cf315b74d 100644 --- a/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua +++ b/Master/texmf-dist/scripts/lua-physical/physical-dimension.lua @@ -3,7 +3,7 @@ The Dimension class keeps track of the dimenionality of a physical quantity. It can be used to perform validity checks on mathematical operations such as addition and subtraction. -Copyright (c) 2020 Thomas Jenni +Copyright (c) 2021 Thomas Jenni Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Master/texmf-dist/scripts/lua-physical/physical-number.lua b/Master/texmf-dist/scripts/lua-physical/physical-number.lua index 8c278aacfee..bd6a01e4513 100644 --- a/Master/texmf-dist/scripts/lua-physical/physical-number.lua +++ b/Master/texmf-dist/scripts/lua-physical/physical-number.lua @@ -2,7 +2,7 @@ This file contains the number class which allows to do calculations with uncertainties. -Copyright (c) 2020 Thomas Jenni +Copyright (c) 2021 Thomas Jenni Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -39,12 +39,12 @@ setmetatable(Number, { -- allows to set a default uncertainty, i.e. (5.6) will become (5.60 +/- 0.05) Number.defaultUncertainty = 0.5 --- Switch for writing uncertainty or not -Number.omitUncertainty = false +-- Switch for writing the uncertainty or not +Number.omitUncertainty = true -- If true, the plus-minus notation will be used, otherwise the uncertainty -- will be appended to the value in parentheses. -Number.seperateUncertainty = false +Number.seperateUncertainty = true -- number format "decimal" or "scientific" Number.DECIMAL = 0 @@ -196,12 +196,20 @@ end -- plus minus notation, i.e. (5.040 +/- 0.001) -function Number:toPlusMinusNotation(format) +function Number:toPlusMinusNotation(format, parenthesis, pmsign) if format == nil then format = Number.format end + if parenthesis == nil then + parenthesis = true + end + + if pmsign == nil then + pmsign = " +/- " + end + local m, e = self._frexp(self._x) local dm, de = self._frexp(self._dx) @@ -216,13 +224,15 @@ function Number:toPlusMinusNotation(format) -- In the decimal format, the numbers are given as decimals, i.e. (0.02 +/- 0.001) if format == Number.DECIMAL then if de - udigit >= 0 then - str = self._flt2str(self._x, 0).." +/- "..self._flt2str(self._dx, 0) + str = self._flt2str(self._x, 0)..pmsign..self._flt2str(self._dx, 0) else local digits = math.abs(-de + udigit) - str = self._flt2str(self._x, digits).." +/- "..self._flt2str(self._dx, digits) + str = self._flt2str(self._x, digits)..pmsign..self._flt2str(self._dx, digits) end - str = "("..str..")" + if parenthesis then + str = "("..str..")" + end -- In the scientific format, the numbers are written with powers of ten, i.e. (2.0 +/- 0.1) e-2 elseif format == Number.SCIENTIFIC then @@ -232,13 +242,15 @@ function Number:toPlusMinusNotation(format) de = de - e if de >= 0 then - str = self._flt2str(m, 0).." +/- "..self._flt2str(dm, 0) + str = self._flt2str(m, 0)..pmsign..self._flt2str(dm, 0) else local digits = math.abs(-de + udigit) - str = self._flt2str(m, digits).." +/- "..self._flt2str(dm, digits) + str = self._flt2str(m, digits)..pmsign..self._flt2str(dm, digits) end - str = "("..str..")" + if parenthesis then + str = "("..str..")" + end if e ~= 0 then str = str.."e"..e @@ -341,6 +353,24 @@ function Number:__tostring() end +-- convert number to a string +function Number:tosiunitx() + + if self._dx == 0 then + return tostring(self._x) + + elseif Number.omitUncertainty then + return self:toOmitUncertaintyNotation() + + elseif Number.seperateUncertainty then + return self:toPlusMinusNotation(Number.format, false, "+-") + + else + return self:toParenthesisNotation() + end + +end + -- equal -- Two physical numbers are equal if they have the same value and uncertainty function Number.__eq(n1,n2) diff --git a/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua b/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua index d89fdd2836b..875a2ee38d3 100644 --- a/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua +++ b/Master/texmf-dist/scripts/lua-physical/physical-quantity.lua @@ -1,7 +1,7 @@ --[[ This file contains the quantity class -Copyright (c) 2020 Thomas Jenni +Copyright (c) 2021 Thomas Jenni Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -424,10 +424,18 @@ function Quantity:tosiunitx(param,mode) end if mode == Quantity.SIUNITX_SI then - return "\\SI"..param.."{"..tostring(self.value).."}".."{"..self.unit:tosiunitx().."}" + if type(self.value) == "number" then + return "\\SI"..param.."{"..tostring(self.value).."}".."{"..self.unit:tosiunitx().."}" + else + return "\\SI"..param.."{"..self.value:tosiunitx().."}".."{"..self.unit:tosiunitx().."}" + end elseif mode == Quantity.SIUNITX_num then - return "\\num"..param.."{"..tostring(self.value).."}" + if type(self.value) == "number" then + return "\\num"..param.."{"..tostring(self.value).."}" + else + return "\\num"..param.."{"..self.value:tosiunitx().."}" + end elseif mode == Quantity.SIUNITX_si then return "\\si"..param.."{"..self.unit:tosiunitx().."}" diff --git a/Master/texmf-dist/scripts/lua-physical/physical-unit.lua b/Master/texmf-dist/scripts/lua-physical/physical-unit.lua index 65c016449b0..5c20722fe15 100644 --- a/Master/texmf-dist/scripts/lua-physical/physical-unit.lua +++ b/Master/texmf-dist/scripts/lua-physical/physical-unit.lua @@ -2,7 +2,7 @@ This file contains the unit class. It task is keeping track of the unit terms. -Copyright (c) 2020 Thomas Jenni +Copyright (c) 2021 Thomas Jenni Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Master/texmf-dist/scripts/lua-physical/physical.lua b/Master/texmf-dist/scripts/lua-physical/physical.lua index 8c8d30171b8..69646873576 100755 --- a/Master/texmf-dist/scripts/lua-physical/physical.lua +++ b/Master/texmf-dist/scripts/lua-physical/physical.lua @@ -3,8 +3,8 @@ lua-physical Author: Thomas Jenni -Version: 1.0.3 -Date: 2020-09-09 +Version: 1.0.5 +Date: 2021-05-08 License: MIT -- cgit v1.2.3