Is there a Objective-C or C math function to constrain a variable between a Min and a Max? What I am looking for is a math function that constrains a primitive variable between a minimum and a maximum value in only one single function call, if it exists, in the standard math libraries for Objective-C.  I currently use:  float constrainedValue = fminf( maxValue, fmaxf( minValue, inValue ) );   Since I know that both fminf and fmaxf could potentially have instruction jumps or branches, it seems likely there could be a simple routine that could conjoin both of these operations into one, optimized function.
Fastest way to clamp a real (fixed/floating point) value? 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).
Does payment in goods count as "income" for tax purposes? Can someone help me elucidate the definition of "income" from a tax perspective? More specifically, if Joe is paid for his work in avocados instead of dollars, then would Joe be exempt from paying any income tax for the year? Or would the value of avocados earned for the year be translated into dollars which would then be considered Joe's annual income? If so, what guidelines would one use to make this translation? (Make the assumption that Joe does not sell the avocados (for dollars) at a later date and either eats them or trades them for other real property)  What if he was paid in gold instead of avocados? Is there a way to start over?  No spoilers here, but after a certain point in the game I wish I had done something different, so I'd like to perhaps start over and make some different decisions based on my current game play experience. Possible Duplicate:          This is something I haven't quite figured out yet, but I have been using function(){}() just because my VIM syntax highlight screws up if I add the parenthesis, although I've seen (function(){})() around many times, maybe its an IE thing?  edit:  var singleton = function() {     // code }();  var singleton = (function() {     // code })(); Extremely difficult logic question using conditional statement In this problem, we will only consider (real-valued) functions with domain $\mathbb{R}$. We define two new concepts. Let $f$, and $g$ be two functions.  We say $f$ is a rival of $g$ if   &emsp;&emsp;&emsp;&emsp; $\exists x\in \mathbb{R} \ \text{s.t.} \ \forall y\in \mathbb{R}, x \lt y \implies \lvert f(x)- g(x)\rvert\lt\lvert f(y)-g(y)\rvert$    We say $f$ is a frenemy of $g$ if  &emsp;&emsp;&emsp;&emsp; $\forall x\in\mathbb{R} \ \text{s.t.} \ \  x \lt y \ \ \text{AND} \ \ \lvert f(x)-g(x)\rvert \lt \lvert f(y)-g(y)\rvert$  Below are four claims. Which ones are true and which ones are false? If a claim is true prove it. If a claim is false, show it with a counterexample.  a) If $f$ and $g$ are any two functions and $f$ is a rival of $g$ then $f$ is a frenemy of $g$. b) If $f$ and $g$ are any two functions and $f$ is a frenemy of $g$ then $f$ is a rival of $g$. If $f$ and $g$ are any two functions and $f$ is a rival of $g$, then $g$ is a rival of $f$. Let $f$, $g$, and $h$ be any three functions. If $f$ is a frenemy of $g$ and $g$ is a frenemy of $h$ then $f$ is a frenemy of $h$  What are the four claims stating? Especially for c), the concept is not even present I am having a misunderstanding on how to solve them? Why is posterior density proportional to prior density times likelihood function? According to Bayes' theorem, $P(y|\theta)P(\theta) = P(\theta|y)P(y)$. But according to my econometric text, it says that $P(\theta|y) \propto P(y|\theta)P(\theta)$. Why is it like this? I don't get why $P(y)$ is ignored. Forcing smoothness of regression coefficients As far as we know the gaze of the basilisk will instantly kill someone or eventually petrify him/her in case the gaze is somehow softened or reflected.   But why would it melt the film in Colin's camera? The film is just plastics with some specific chemicals.   A bit broader question would be - is the some information that the basilisk's gaze is somehow destructive to non-alive objects too and under what circumstances could it happen? What is the term for the grandson of my aunt? Keytool Signing Problem: Keystore was tampered with, or password was incorrect Enumerate paragraphs and subparagraphs like sections but with letters I'm using pandoc and in my template.tex exists this code to make the paragraphs and subparagraphs to behave like sections.  % Redefines (sub)paragraphs to behave more like sections \ifx\paragraph\undefined\else \let\oldparagraph\paragraph \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}} \fi \ifx\subparagraph\undefined\else \let\oldsubparagraph\subparagraph \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}} \fi   This code generate number like this:  1. chapter  1.1 section  1.1.1 subsection  1.1.1.1 subsubsection  1.1.1.1.1 paragraph  1.1.1.1.1.1 subparagraph   How to change this code to enumerate with letter like this:  1. chapter  1.1 section  1.1.1 subsection  1.1.1.1 subsubsection  1.1.1.1.a paragraph  1.1.1.1.a.a subparagraph Word for someone who pays attention to details Is it feasible to compile Python to machine code? What is the difference between the dashed and solid attack bars? I was flipping through my Pokemon list to see which kind of attacks they had, and I notice there was a small different between the attacks. Some attacks contained a dashed blue bar where as others contained a solid blue bar.   What is the difference and significance between the two? Escape velocity from a rotating black hole Under Newton, the escape velocity is  $$v_{esc} = \rm c \ \sqrt{r_s/r}$$  where $\rm r_s=2 \ GM/c^2$. In the nonrotating relativistic case (the Schwarzschild case) the radial escape velocity is the same:  $$v^{\parallel}_{esc} = \rm c \ \sqrt{r_s/r}$$  which is the speed of light, $v={\rm c}$, at the event horizon at $\rm r=r_s$. Since the photon sphere, where an object with $v={\rm c}$ would not escape, but be captured into orbit, is at $r=3 \ {\rm GM/c^2}$, the transverse escape velocity is  $$v^{\perp}_{esc} = \rm c \ \sqrt{r_s/r}\div \sqrt{1-r_s/r}$$  and for the observed (shapiro delayed) velocity ${\rm v}$ the transformation is  $${\rm v}^{\perp}=v^{\perp} \ \sqrt{\rm 1-r_s/r} \ , \ \ {\rm v}^{\parallel}=v^{\parallel} \ (\rm 1-r_s/r)$$  so the observed angular motion is the same as with Newton, yet locally higher, while the observed radial motion is slowed down because of the radial length contraction and time dilation.  But what about the Kerr case where the rotation is significant and the event horizon is at $\rm r=(1+\sqrt{1-a^2}) \ {\rm GM/c^2}$ instead of $\rm r=r_s$?  A testparticle which is locally at rest and therefore corotating with the angular velocity of the frame dragging  $${\Omega = \rm d \phi/ {\rm d t} = {\rm 2 \ a \ r/((a^2+r^2)^2-a^2 (a^2+(r-2) \ r) \sin ^2(\theta ))}}$$  should experience the time dilation factor  $$\rm \dot t = {\rm d t}/ {\rm d}\tau = \sqrt{{\rm ((a^2+(r-2) \ r) (a^2 \cos ^2(\theta )+r^2))/((a^2+r^2)^2-a^2 (a^2+(r-2) \ r) \sin ^2(\theta ))}}$$  relatively to the far away observer, so multiplying $\Omega$ with $\rm \dot t$ should give the local frame dragging angular velocity, which, multiplied with the $\rm \sqrt{x^2+y^2}$ value of the Boyer-Lindquist to cartesian transformation should give the transverse velocity - this is slightly below $\rm c$ for a maximaly rotating black hole (with $\rm a = 1$ - at the edge of the outer equatorial ergosphere where $\rm r=1$ and $\rm R=\sqrt{r^2+a^2}$).  But how do I find the radial and total escape velocity, and what are the rules to convert the shapiro-delayed coordinate velocities $\rm d r/d t \ , \ d \phi/d t \ , d \theta/d t$ to the local 3-velocity components $v^{\parallel}$ and $v^{\perp}$ of a test particle (local meaning relatively to a frame dragged probe with contant $\rm r$)? The radial length contraction seems a bit different than in the Schwarzschild-case, where it is the same as the gravitational time dilation factor... What package should I use to typeset units? I want to use some constants, height and width, when creating an ellipse but it won't work with \newcommand. Here is a minimal example:  \documentclass[12pt, a4paper]{article}  \usepackage{amsthm, tikz} \usetikzlibrary{arrows, shapes, trees, positioning} \begin{document}  \begin{figure} \centering \begin{tikzpicture}       \newcommand*{\width}{2}%     \newcommand*{\height}{0.5*\width}%      \draw[fill=gray!40] (0, 0) ellipse (\width and \height); \node (Y) at (0,0) {\(Y\)};      \end{tikzpicture} \end{figure}  \end{document}    I get the following error:  error: line 14:  Package PGF Math Error: Unknown operator `a' or `an' (in '2and 0.5*2'). ...ay!40] (0,0) ellipse (\width and \height) How to hyperlink only the year part when using natbib and hyperref I am using the natbib and hyperref packages:  \usepackage{natbib}  \usepackage[pagebackref=true, plainpages=false, bookmarks, bookmarksnumbered, colorlinks, linktocpage=true, linkcolor=blue, citecolor=blue, filecolor=black, urlcolor=blue]{hyperref}   With my current settings (above) both the name and the year are hyperlinked.  My question is, whether there is a way to hyperlink (or color) only the year-not the author(s).   I have the impression reading this post  that biblatex does it by default. However changing to biblatex is not an option for me at this point.  Any helpful comments will be greatly appreciated. Is there a word which describes terms that are spelled like a particular pronunciation? Some examples: &quot;never&quot; might be written as &quot;neva&quot; &quot;I don't know&quot; is sometimes written as &quot;iono&quot; or &quot;I dunno&quot; on various internet media. My question is: is there a word for this particular technique of spelling a term in the way it is (sometimes) pronounced? As an example I have a BSB file from NOAA which is a navigational map. The map has a SRS of WGS84 and a Mercator projection.  I initially translate the file from BSB format to GTiff format using the following command:  gdal_translate -of GTiff 18554_1.kap noaa.tif  I can view this GTiff file using Paint Shop Pro quite fine. I then translate the file from GTiff format to VRT format using the following command:  gdal_translate -of vrt –expand rgba noaa.tif noaa.vrt  I then try to generate a tile matrix set using the following command:  gdal2tiles.py noaa.vrt tiles_folder  Where the map tiles are located in tiles_folder. If I try to open the openmaps.html or google.html, the map zoom in and out looks good. However, on tiles generator like MBTiles, I see tiles swap. See the image below. I am pulling my hair off to get the tiles to line up. I am guessing it is projection error. I am not understanding those projection types. It would great someone can explain it while finding the error. I am planning to use on a tiling  like this. By the way, on GDAL how do I specify the BSB (reference) file that is associated with KAP (data) file? I have seen cases where only one BSB file referred by multiple KAP files. How can I export a list containing e-mail addresses for everyone that has sent me an e-mail?  I have all of the messages archived.