I know in latex it is possible to use counters which are based on integers. Is there also some way to define a floating point register to perform simple arithmetic operations?  Basically I would need some way to write something like  \newreg{myx} \setreg{myx}{0.0} \addreg{myx}{0.5} \addreg{myx}{-0.25} \valuereg{myx} % this expands to 0.25
39025
I am looking for a method to do minimal floating point / integer calculations in LaTeX, not for the purpose of package writing, but for the production of actual text.  Here is an example to illustrate. Given the following input text   The experiment included running a battery of \bind{T}{21} tests  on \bind{S}{13} subjects, for a total of \bind{V}{T*S} expected values.  However, since \bind{F}{37} values were defective, our successful   measurement rate per subject was \use{100*round((V-F)/T,2)}\%   it would be nice if was converted to:   The experiment included running a battery of $21$ tests  on $13$ subjects, for a total of $273$ expected values.  However, since $37$ values were defective, our successful   measurement rate per subject was $86$\%.   Where \bind{C}{expression} defines a new constant C whose value is expression, and returns C, while \use{C} simply returns the value of C.  Any tips?  I am aware of the spreadtab package and this question: , but I am looking for something more.
61612
I'm looking for a  way to convert numbers to string format, dropping any redundant '.0'   The input data is a mix of floats and strings. Desired output:  0   --> '0'  0.0 --> '0'  0.1 --> '0.1'  1.0 --> '1'  I've come up with the following generator expression, but I wonder if there's a faster way:  (str(i).rstrip('.0') if i else '0' for i in lst)   The truth check is there to prevent 0 from becoming an empty string.  EDIT: The more or less acceptable solution I have for now is this:  ('%d'%i if i == int(i) else '%s'%i for i in lst)   It just seems strange that there is no elegant way to handle this (fairly straightforward) case in python.
23841
Building on , I was thinking about sensible, intuitive ways to do that Programming 101 chestnut of displaying integers in base-2 form.  This is the best I came up with, but I'd like to replace it with a better algorithm, or at least one that should have screaming-fast performance.    def num_bin(N, places=8):     def bit_at_p(N, p):         ''' find the bit at place p for number n '''         two_p = 1 &lt;&lt; p   # 2 ^ p, using bitshift, will have exactly one                          # bit set, at place p         x = N &amp; two_p    # binary composition, will be one where *both* numbers                          # have a 1 at that bit.  this can only happen                           # at position p.  will yield  two_p if  N has a 1 at                           # bit p         return int(x &gt; 0)      bits =  ( bit_at_p(N,x) for x in xrange(places))     return "".join( (str(x) for x in bits) )      # or, more consisely      # return "".join([str(int((N &amp; 1 &lt;&lt; x)&gt;0)) for x in xrange(places)])
78747
I want to add two hexadecimal variables in a bash script.  I want them to start as hex and end in hex, not decimal.    What I've come up with so far is a bit of a round about hack. Is there a better or more elegant solution?  BASE=0xA000  OFFSET=0x1000  NEW_BASE=$(( $BASE + $OFFSET ))  NEW_BASE=`printf "0x%X\n" $NEW_BASE`  echo $NEW_BASE  0xB000
82915
For example, the standard division symbol '/' rounds to zero:  &gt;&gt;&gt; 4 / 100 0   However, I want it to return 0.04. What do I use?
113353
I'm working with large numbers that I can't have rounded off.  Using Lua's standard math library, there seem to be no convenient way to preserve precision past some internal limit.  I also see there are several libraries that can be loaded to work with big numbers:      (might be identical to #2)  (but I can't find any source)   Further, there are  in C that could be called from Lua, if the bindings where established.  Have you had any experience with one or more of these libraries?
75350
Is it possible to have automatic rounding of numbers in a table?  Say that I have this, made in the usual way with a tabular environment:  pi  | 3.14592654 e   | 2.7182818284 phi | 1.6180339887   Can I control how many significant digits are shown without truncating the numbers manually myself?   So for example, if I need four significant digits, the numbers should appear as  pi  | 3.1459 e   | 2.7183 phi | 1.6180   Bonus points for actually rounding the numbers according to the usual rules without simply truncating them.    I understand this is probably non-trivial, so here's a relaxed version that will also work in my circumstances (all numbers have one and the same precision and character count):  (How) Can I control how many characters are rendered in a column of a table?  So if I define the text in the columns as:  \begin{tabular} % some black magic column definition    text &amp; alongword\\    text &amp; anotherlongword\\    text &amp; morelongwords\\ \end{tabular}   I'd like to get something like:  text along text anoth text morel   I know there are non-TeX ways to do this, and I will probably resolve to writing a script if all else fails, but I'm curious whether there's a way to do it solely with TeX &amp; friends.
33306
Hey! I was looking at this code at   I noticed that in some situations they used hex numbers, like in line 134:  for (j = 1; val &amp;&amp; j &lt;= 0x80; j &lt;&lt;= 1, q++)   Now why would they use the 0x80? I am not that good with hex but I found an online hex to decimal and it gave me 128 for 0x80.  Also before line 134, on line 114 they have this:  small_n = (n &amp; 0xffff0000) == 0;   The hex to decimal gave me 4294901760 for that hex number. So here in this line they are making a bit AND and comparing the result to 0??  Why not just use the number? Can anyone please explain and please do give examples of other situations.  Also I have seen large lines of code where it's just hex numbers and never really understood why :(
60259
What is the difference between decimal, float and double in .NET?  When would someone use one of these?
87887
I need a simple floating point rounding function, thus:   double round(double);  round(0.1) = 0 round(-0.1) = 0 round(-0.9) = -1   I can find ceil() and floor() in the math.h - but not round().  Is it present in the standard C++ library under another name, or is it missing??
63266
\num{100000} prints 100 000  I want to have 1 00 000.  Question: How to set siunitx package to do the above?  Some more  \num{1000} => 1 000  \num{10000} => 10 000  \num{100000} => 1 00 000  \num{1000000} => 10 00 000  \documentclass[12pt]{article} \usepackage{siunitx} \sisetup{group-separator = {,}}  \begin{document}  \num{1000}  \num{10000}  \num{100000}  \num{1000000}  \num{10000000}  \num{100000000}  \num{1000000000}  \SI{1000000000}{m}  \end{document}   The exact rules are described on the :     The Indian Numbering System uses separators differently from the Arabic system; besides the three least significant digits of the integer part, a comma divides every two rather than every three digits.
99038
Which libraries for Java are there that have a fast implementation for floating point or fixed point operations with a precision of several thousands of digits? How performant are they?  A requirement for me is that it implements a multiplication algorithm that is better than the naive multiplication algorithm that takes 4 times as much time for a 2 times larger number of digits (compare ).
11634
Sorry for asking such a basic question - but is there an actual term for the numbers that appear before and after the decimal point?  Example:  25.18  I know the 1 is in the tenths position, the 8 is in the hundredths position. are there singular terms which apply to all of the numbers that appear both before and after the decimal point?  I'm building a billing system, storing dollars and cents as integers (in separate columns), but for other currencies "dollars" and "cents" are not the correct terms = ).  Thanks!
28119
What is the "best LaTeX practices" for writing absolute value symbols?  Are there any packages which provide good methods?  Some options include |x| and \mid x \mid, but I'm not sure which is best...
111701
I'm messing around with some C code using floats, and I'm getting 1.#INF00, -1.#IND00 and -1.#IND when I try to print floats in the screen. What does those values mean?  I believe that 1.#INF00 means positive infinity, but what about -1.#IND00 and -1.#IND? I also saw sometimes this value: 1.$NaN which is Not a Number, but what causes those strange values and how can those help me with debugging?  I'm using  which I believe uses  representation for float point numbers.  Can someone list all those invalid values and what they mean?
79687
This is a wild one: can anyone write a code that converts a number into the corresponding word? e.g.:  4 -&gt; 'four' 31 -&gt; 'thirty-one'   and so on. Obviously, it is not enough to build an array in which you can store the numbers and the word associated with it and then just print instead of the number the stored word. What complicates matters more, are numbers like 11 ('eleven'). I intend to use it for numbering equations. So, anybody up to it?
44106
Is there a more efficient way to clamp real numbers than using if statements or ternary operators? I want to do this both for doubles and for a 32-bit fixpoint implementation (16.16). I'm not asking for code that can handle both cases; they will be handled in separate functions.  Obviously, I can do something like:  double clampedA; double a = calculate(); clampedA = a &gt; MY_MAX ? MY_MAX : a; clampedA = a &lt; MY_MIN ? MY_MIN : a;   or  double a = calculate(); double clampedA = a; if(clampedA &gt; MY_MAX)     clampedA = MY_MAX; else if(clampedA &lt; MY_MIN)     clampedA = MY_MIN;   The fixpoint version would use functions/macros for comparisons.  This is done in a performance-critical part of the code, so I'm looking for an as efficient way to do it as possible (which I suspect would involve bit-manipulation)   EDIT: It has to be standard/portable C, platform-specific functionality is not of any interest here. Also, MY_MIN and MY_MAX are the same type as the value I want clamped (doubles in the examples above).