A word for a value between 0 and 1 (inclusive)
english.stackexchange.com
english.stackexchange.com
EDIT: Some of you asked what about languages that don't support such more constrained types, so to answer all of you here: different languages have different capabilities, of course, so while some may make what I proposed trivial, in others it would be almost or literally impossible. However, I believe most of the more popular languages support creation of custom data types? So the idea (for those languages at least) is quite simple - hold the value as a float, but wrap it in a custom data type that makes sure the value stays within bounds through accessor methods.
function FuncName(UnitInterval accuracy)UnitIntervalNumber would be better, but it's too long. Something like UnitNumber or UnitFloat could maybe work.
I have actually used intervals, and should have realised this sooner. But I just had my first cup of coffee...
function FuncName(NormalizedFloat accuracy)
In languages with operator overloading you can make NormalizedFloat a proper class with asserts in debug version and change it to an alias of float in release version.Similarly I wonder why gemoetry libraries don't define separate Point class and Vector class, they almost always use Vector class for vectors and points.
I understand math checks out, and sometimes you want to add or multiply points, for example:
Pmid = (P0 + P1) / 2
But you could cast in such instances: Pmid = (P0 + (Vector)P1)/ 2
And the distinction would surely catch some errors. Point - Point = Vector
Point + Point = ERROR
Vector +/- Vector = Vector
Point +/- Vector = Point
Point * scalar = ERROR
Vector * scalar = Vector
Point */x Point = ERROR
Vector * Vector = scalar
Vector x Vector = VectorThis got me thinking: What about a situation where the accuracy is given in a real-life unit. For example, the accuracy of a GPS measurement, given in meters. I've sometimes used names like 'accuracyInMeters' to represent this, but it felt a bit cumbersome.
Edit: Thinking more about it, I guess you could typealias Float to Meters, or something like that, but also feels weird to me.
The newtype wrapper doesn't show up at runtime, only at compile time. It can be set up in such a way that the compiler complains about adding GpsInMeters to GpsInMiles naively.
Another thing you can do is define a "METER" constant equal to 1. You can then call your function like this: func(1.5 * METER), and when you need a number of meters, you can do "accuracy / METER". The multiplication and division should be optimized away.
Good thing about that is that you can specify the units you want, for example you can set FOOT to 0.3048 and do "5. * FOOT" and get back your result in centimeters by doing "accuracy / CENTIMETER". The last conversion is not free if the internal representation is in meter but at least, you can do it and it is readable.
If you are going to use such distances a lot, at least in C++, you can get a bit of help from the type system. Define a "distance" class operator overloads, constants and convenience functions to enforce consistent units. Again, the optimizer should make it not more costly than using raw floats if that's what you decide to use as an internal representation.
This begs an interesting tangential question: Which programming languages allow such resticted intervals as types?
type percentage:=int[0,100] type hexdigit:=int[0,15] …
since this might be overkill, sane programming languages might encourage assert statements inside the functions.
So instead of
func call(Person person){} you just have func call(person){}
where person is a known type AND the variable name.
In that scenario 'accuracy' would be a type with known value between 0 and 1.
func call(person#1 person#2){}
function call(person#sender person#receiver)
And at that point we're back to the square one, just remove the # :){person}
Is an object person with key person and value person of type Person
https://www.joelonsoftware.com/2005/05/11/making-wrong-code-...
You'd be surprised where the support is. In C#, you would declare a struct type with one read only field of type double, and range validation (x <= x <= 1) in the constructor.
this is the "value object" pattern. http://wiki.c2.com/?ValueObject
Yes there's a bit of boilerplate - especially since you might want to override equality, cast operators etc. But there is support. And with a struct, not much overhead to it.
"public Customer GetById(CustomerId id)" instead of "public Customer GetById(string id)" when only some strings (e.g. 64 chars A-Z and 1-9) are valid customer ids.
Compile-time validation would be ideal, but validation at the edges, well before that method, is good enough.
Usually cured by using Value objects. I wish this done more in OO code.
Could it be better supported in these languages? Yes, for sure. But is it true that "these language do not support such a type" at all? No.
Can float types even support 0, 1 inclusive? You just can't represent natural numbers like that with floats...
Fortunately, my preferred programming language, Raku, makes creating this sort of subset trivially easy[0]:
subset UnitInterval of Real where 0 ≤ * ≤ 1
[0]: https://docs.raku.org/language/typesystem#index-entry-subset...Say you need to represent velocity in a transportation simulation. You could have a function, velocity, that looks like this:
double velocity(double v, char * of_what)
You use it to wrap constrained values. E.g., double v_jogger = velocity(8.0, "human");
double v_car = velocity(65.0, "city car");
velocity() simply returns the first argument, after doing validity checking based on the second argument.You probably couldn't reasonably use this everywhere that you would use actual constrained types in a language that has them, but you could probably catch a lot of errors just using them in initializers.
@Clamping(0...14) var pH: Double = 7.0
https://nshipster.com/propertywrapper/#implementing-a-value-... real<lower = 0, upper = 1> accuracy;It seems disingenuous to me to suggest that anyone using other languages do not have this problem. And really, there are quite a few languages to not have this form of typing, and even some reasons for a language to not want this form of typing.
So please, don't answer a question by saying "your questions is wrong" it is condescending and unhelpful.
"here is what seems like a better question" is helpful, especially in a discussion forum separate from the original Q/A.
But if "here is what seems like a better question" is the _only_ response or drowns out direct responses, then thats still frustrating.
> condescending
As a man who sometimes lacks knowledge about things, when I ask a question, please please please err on the side of condescending to me rather than staying silent. (No, I don't know how you should remember my preferences separately from the preferences of any other human)
I merely wanted to point out that, in my opinion, this property should be reflected in parameter type, rather than the name. Just like, if we wanted a parameter that should only be a whole number, we wouldn't declare it as a float and name it "MyVariableInteger" and hope that the callers would only send integers.
You mentioned that there are quite a few languages that do not permit what I proposed, would you mind specifying which ones exactly? The only one that comes to my mind is assembly?
To avoid that, you need to document that the value should be between 0 and 1, and you could do that with a comment line (which the OP wanted to avoid), or by naming the variable or type appropriately: And that takes us back to the original question. (Whether the concept is expressed in the parameter name or parameter type (and its name) is secondary.)
I'm not sure I understand this. See below, but the larger point here is that the type can never lie -- names can and often do because there's no checking on names.
I think what is being proposed is something similar to
newtype Accuracy = Accuracy Float
and then to have the only(!) way to construct such a value be a function mkAccuracy :: Float -> Maybe Accuracy
which does the range checking, failing if outside the allowable range.Any functions which needs this Accuracy parameter then just take a parameter of that type.
That way you a) only have to do the check at the 'edges' of your program (e.g. when reading config files or user input), and b) ensure that functions that take an Accuracy parameter never fail because of out-of-range values.
It's still a runtime-check, sure, but but having a strong type instead of just Float, you can ensure that you only need that checking at the I/O edges of your program and absolute assurance that any Accuracy handed to a function will always be in range.
You can do a similar thing in e.g. C with a struct, but unfortunately I don't think you can hide the definition such that it's impossible to build an accuracy_t without going through a "blessed" constructor function. I guess you could do something with a struct containing a void ptr where only the implementation translation unit knows the true type, but for such a "trivial" case it's a lot of overhead, both code-wise and because it would require heap allocations.
Having proper compile time (or runtime if compile time isn't feasible) checks is of course the better solution, but not always practical either because of lack of support in the desired language, or rarely because of performance considerations.
There's a place for type aliases, but IMO that place is shrinking in most languages that support them, e.g. Haskell. With DerivingVia, newtypes are extremely low-cost. Type aliases can be useful for abbreviation, but for adding 'semantics' for the reader/programmer... not so much. Again, IMO. I realize this is not objective truth or anything.
Of course, if you don't have newtypes or similarly low-cost abstractions, then the valuation shifts a lot.
EDIT: Another example: Scala supports type aliases, but it's very rare to see any usage outside of the 'abbreviation' use case where you have abstract types and just want to make a few of the type parameters concrete.
The point remains that the fact a given parameter's valid values are [0,1] is not a function of it's name. You can check the values within the method and enter various error states depending on the exact business rules.
you have a very valid point but it would come across even more effectively without that part, i believe.
No, most don't, except if you go into building custom classes.
That seems a very elaborate way to say “No" when the answer is really “Yes”.
Or in other words, a succint way to say "Technically yes, but practically useless, so no".
type NormalisedFloat = number
Admittedly it doesn't add any actual value checking, but it does convey the information when you look at the parameter definition.-- BetweenZeroAndOne.elm
module BetweenZeroAndOne exposing (get, set)
type BetweenZeroAndOne = BetweenZeroAndOne Float
set : Float -> BetweenZeroAndOne set value = BetweenZeroAndOne (Basics.clamp 0.0 1.0 value)
get : BetweenZeroAndOne -> Float get (BetweenZeroAndOne value) = value
[0] https://en.wikipedia.org/wiki/Opaque_data_type#:~:text=In%20....
It's the same question of, how can you convert a string to a Regexp type if not all strings are valid Regexps?
> In other words, the parameter should not be a float, but a more constrained type that allows floats only in [0,1]
It's a value check, not a type check.
I propose "pun" - proportion of unity, or "p(er) un".
I like verbosity!
Or use a dependent type language. Maybe Idris? Then something like Between(0,1) I guess.
-- A float between 0 and 1, inclusive.
type UnitInterval = Float
foo :: UnitInterval -> SomeResultPresumably
foo accuracy = ...
i.e. I think the essential problem in the SO question is solved, even though we have no additional type safety.A language without type synonyms could do just as well with CPP defines
You’d have to decorate/call manually in your functions so it’s not watertight, but at least it’s DRY.
I wish I were commenting here with an answer, but I don't have one. "brightness01" is a common naming convention for values of this type in computer graphics programming, but niche enough that it got raised in review comments by another gameplay programmer.
I frequently run into programming related naming issues (who doesn't eh?). But I struggle to find accurate search terms to help answer them...and the results are usually downed out by non-technical related language Q&A's
E.g. I was trying to name a table yesterday that would store events related to boxes, pallets, containers and vessels and was looking for a generic name to group them, e.g. goods_events, entity_events, object_events, domain_object_events etc. but I had no idea how to phrase my question and not get a bunch of junk back
Would be awesome if you could tweak some suggestion algo to be trained on repo's specific to your domain and have it spit out suggestions based on human language questions, e.g. gpt3 but focussed on some domain.
Woo, that's a tough one. Even as a native speaker, I'd be hard-pressed to find one word in English that describes all these similar but different terms.
I looked up some of these in a dictionary for definitions and synonyms. OK, the word "holder" seems to be the most general term that includes all these types of objects.
So I'd name it "holder_events_table", with a column "holder_type" being box, pallet, etc.
This issue of finding precise naming is related to "ontologies", how to establish an organization of agreed-upon terms to classify objects in the world. I agree with you, it would be valuable if there was a community-developed reference where we could search for the most appropriate names of things.
but yeah, naming things...wonder how much time I've spent pondering over names in my career (probably too much haha)
If you don't have a relationship with your stakeholders because your company has paid lots of money to become Agile[1][2], then you are indeed in trouble.
[1] https://www.youtube.com/watch?v=a-BOSpxYJ9M
[2] https://www.fgcquaker.org/resources/form-without-substance
So you keep info about these separately already or in some common table with discriminator? Then maybe:
boxes -> box_events, containers -> container_events,...
Or:
units(type:{box, container,...}) -> unit_events
In your case, I looked at synonyms for "containers" and found some likely candidates such as "holders" or "receptacles", so `receptacle_events`.
Think about why these 4 things are of interest. What aspect of them is it you're working with?
If that aspect has a name, that might be the basis if a good name that reflects the purpose of your code.
https://github.com/Mister-Meeseeks/words-for-variables
(Pull requests are welcome, if anyone else has good suggestions for candidates on the list.)
Well, I was inspired enough by this idea to create a sub-reddit for the discussion of specific variable naming challenges. Hopefully it catches on.
r/namemyvariable
Hmm feels a bit weird, maybe r/namingvariables haha already think'n bout re-naming the naming sub lolz
* https://cs.stackexchange.com/
* https://softwareengineering.stackexchange.com/
So the question to ask onesself is whether one wants answers to a programming language question on how to name a variable from an audience of linguists or from an audience of software engineers. (-:
(A unit interval is the set [0, 1], whereas the asker wants to know a name for an element of it.)
Also, Unit Interval is only an answer to this exact question, not a class of questions to which this one belongs. If the range was [0,5] then you couldn't even shorten it with Unit Interval.
IEEE 754 sort-of has that as a part of a float, too (https://en.wikipedia.org/wiki/Significand), and people use the term “mantissa” for it, but it has to special-case 0.
⇒ barring better suggestions, I think I would stretch the definition of mantissa a bit further.
[0] https://www.curtiswmoore.com/image_detail.php?title=manta.jp...
log(120) = log(1.2 × 10²) = 2.079,
you could call both the .079 and the 1.2 a mantissa. The first is in the range [0,1) and the second, aka significand, is in [1,10) for base 10.And really one mantissa is just the log of the other.
The linked Wikipedia article just says that the mantissa is “the fractional part.”
Hence the fractional part is always less than 1. Since 0.999... = 1, it is not less than 1, so cannot be the fractional part of any number.
That's what we call data that have been scaled to fit on a tidy axis.
https://en.wikipedia.org/wiki/IEEE_754-1985#Examples
https://wiki.sei.cmu.edu/confluence/display/c/FLP05-C.+Do+no...
Personally if I saw normalised I would assume scaled by a constant, not offset (as in subtraction).
i.e. say you have a width of 500 and you want to move half way across so you have this value of 0.5 to get 250. By dividing 250 by 500, aren't we in fact normalising it?
The typical, most common, definition of normalisation is value ÷ max possible value, giving a result in [0,1]. (More general definitions of normalisation exist e.g. if you rescale so the standard deviation is a fixed value, or even use non linear rescaling, that could count, but never mind all that.) The parent comment's example of "position along width ÷ total width" certainly fits that bill.
Whenever you divide something by the max of that something, the max is going to have the same units as the original value and you're bound to end up cancelling them. Or put another way, if you rescale 10cm into 0.5, it's certainly not 0.5cm so the units are either dropped or, at least, changed e.g. you could argue you've got 0.5x where x is the unit equal to 20cm.
In general I don't think normalization always includes a sense of being in a bounded interval. From a mathematical perspective you could perhaps say normalization is achieved by multiplying your quantity by a 1D operator. You can't change the dimensionality this way, but are certainly changing 'units' a la mm in the x direction -> m in the x direction for example. I guess what I'm saying is that 'normalized' and the like are not the best fit for the SO question.
If I could take my own shot at the SO challenge from a mathematical perspective it would perhaps be sigmoid. Where the result of a normalization function takes a 1D value and maps it to a similar 1D value, the sigmoid takes a 1D value and maps it to a similar 1D value between (0, 1). So if I want to drop the previous information and only keep the resulting map, I can say 'this is my sigmoided value' - IE it is impossible for it to be outside of that range. Unfortunately sigmoid also connotates a differentiable curve which is extraneous information...
The Wikipedia article you linked to gives two very broad definitions in the lead. The definition covered in the first paragraph is "adjusting values measured on different scales to a notionally common scale", which seems to be what you're talking about.
The definition covered in the second paragraph is "the creation of shifted and scaled versions of statistics", in particular "some types of normalization involve only a rescaling, to arrive at values relative to some size variable". I'm not comfortable with the use of "of statistics" in that second definition: the very first example is in the article standard score [1], which is about a rescaled element of the population, not a rescaled statistic. In any case, outside of statistics, a rescaling is a common meaning for this word, and a rescaled statistic is clearly just a special case of this. I think it was clear from the context that we were talking about this meaning originally. By far the most common case of this is a linear rescaling (including translation) to [0,1] but I was already up front that this is just a special case.
As for your sigmoid comment, I may have misunderstood but it sounds like you're saying that if you have a variable in the range in [0,1] then it can be described as the result of a sigmoid function. My objection to this is the same as my original objection to calling such as variable "normalised": it is a confusing variable name to use unless you actually did get it by applying a sigmoid function to something, not just because it holds a value that could hypothetically be obtained from a sigmoid function (but you didn't).
Certainly, "normalisation" can mean something more general than "rescale to the interval [0,1]".
For example, "rescaling to the interval [0, 20]" might make sense in some contexts and would usually count as a type of normalisation, and would still involve muliplying by a number. But that would be multiplying by (20 / max possible value) rather than the typical case of multiplying by (1 / max possible value).
So normalisation can mean something more general than the most usual common case, but it's not just any old "multiplying it with some other value". It has to specifically for the purpose of rescaling to some fixed, more useful/sensible range.
> say you have a width of 500 and you want to move half way across so you have this value of 0.5 to get 250
This is a great example of multiplication that isn't normalisation! You've multiplied by 0.5 to get the midpoint, but that process isn't normalisation because you've not ended up with some more sensible range. You started with [0,infinity) (the set of all possible widths) and ended up with that same infinite range.
> By dividing 250 by 500
Hang on, I'm confused about your example: are you asking about 500*0.5 (=250) or 250/500 (=0.5)? If it's the latter than that's normalisation, and not even something fancy or general but classic linear rescaling to the interval [0,1]. Yes, that's certainly normalisation.
----
Going back to my original comment: I was talking about values that were in the range 0 to 1 that hadn't reached that range by being multiplied by anything at all; they were just naturally in that range to begin with. For example, a probability would fit this bill.
I'm very clumsily trying to say that if:
width / maxWidth = normalWidth
then: normalWidth * maxWidth = width.
And so, even though we aren't necessary calculating the normal in the second equation, we can still name our variable a 'normal' as rearranging proves that is indeed what the value is.Edit: formatting
(My vote's with "proportion" BTW.)
But normalization doesn't always result in numbers between 0 and 1 and multiplication doesn't always result in numbers between 0 and 100.
Similarly, not all numbers constrained between 0 and 1 have been normalized and not all numbers constrained between 0 and 100 have been multiplied.
Add in the fact that the normalization statisticians most commonly use is z-score standardization (subtracting by the mean and dividing by standard deviation, resulting in data centered around 0), and you're going to end up with a lot of confusion. In fact, this example highlights that while normalization does mean "to scale" it doesn't mean that the result will always be bounded to a particular interval.
Float values between 0 and 1 are very very useful, and I use them all over the place, and I actually thought everyone did (and everyone called them 'Proportions')
Unlike percentages, you can just multiply them with the number you want the 'proportion' of,
Quick, how do you calculate 20% of 50% of 12345!?
(it's (20/100) * (50/100) * 12345)
Ok, now with 'proportions' 0.2 of 0.5 of 12345 :
Why, that's 0.2 * 0.5 * 12345 .
Am I actually the odd one out here?
Instead of x=(foo/100) * (bar/100) * baz
you can do x=foo * bar * baz.
Which is rather more readable!
Probabilities in statistics are also expressed in this manner.
Meanwhile I found out that the Dutch dictionary actually has Perunage for this usage, especially in finance. So maybe that's he term I'll start using?
Of course this rather undersells the elegance and simplicity of perunages, but I'll take it.
[1] https://www.dictionary.com/browse/proportion
[2]https://www.merriam-webster.com/dictionary/proportion (3rd. entry)
A portion of fries can be 80 individuals, the proportion of all fries in the fryer might be 0.1; proportions are often expressed in percentages.
So "the proportion of the population using my tool is 1%" means 1/100, ie 0.01 of a population normalised to unity.
Pro-portion is like pro-rated, it's taken as in comparison to the whole (normalised to the whole, if you like).
"What proportion did you contribute" == what share of the whole did you contribute.
[en-gb native]
Here's another recent HN/Twitter discussion [0] that surprised me and made me think a lot of programmers haven't done much numerical programming.
I'd suggest we call a fuzzy truth value in the interval of [0,1] after its founder Lotfi A. Zadeh, a zadehan or zade for short.
Edit: Fixed Bool to Boole thanks to globular-toast, my internal syntax checker must have auto corrected that one ;)
I like this idea, although I don't think English speakers would know how to pronounce "zadehan" by default. "Zadean" might be better. I don't think it will catch on, though, because "boolean" is really easy to say but "zadean" isn't.
If it was a probability value to which Bayesian operators apply, Zadehan would be a singularly inappropriate name for the type. Types aren't just ranges but they also define the valid operations (whether syntactically functions, methods, or operators) on the type.
I'm not sure if I find Koskos argument convincing, however one could also argue that a bayes is a subtype of a zadeh ;) http://sipi.usc.edu/~kosko/Fuzziness_Vs_Probability.pdf
`accuracy` seems fine to me -- although a more descriptive function name than `FuncName` might suggest a better parameter name as well.
Digging through the dictionary to find the perfect word means that whoever reads this code is likely going to have to do the same -- why would you ask them to do that?
If you aren't referring to a common mathematical or physical concept, and the word you need it isn't a part of your domain language, you're better off with "accurate but slightly vague" over "almost precise" or "precise but obscure".
It seems like the author's need would be better met by readable tests, guard conditions, and -- if this is part of an API -- documentation that describes how `accuracy` is used.
If you can't express it using the features of the language itself (custom domain-specific type, compile contracts?), limit yourself to putting this info into the docs, but keep naming simple.
Don't come up with fancy names. One of the commenters already declared (jokingly??) they'd "call it PropUnity, for proportion of unity, unity being 1".
Holy smokes Batman. As a code maintainer, I imagine encountering "accuracy" (even though it isn't fully accurately named itself) would confuse me somewhat less than "propUnity".
> Naming variables is expressly off-topic here. This question, and the answers to it, are the perfect showcase of why. – RegDwigнt
The link "off-topic" in the notice eventually takes you to the help center which states:
> But please, don’t ask any questions about the following topics. They are out of scope for this site.
> * Naming, including naming programming variables/classes
The question was edited, but the original version was about how to name a variable.
That said, the reason why they're not allowed is not as apparent to me as it is to the mod that made the comment quoted above.
It's so much easier to hit that 'downvote' or 'close' button than to actually try to understand the asker, or compose a meaningful answer, or even explain clearly why a question might truly need work.
So, I see a lot of 'closes' from people who hardly ever answer any questions, and plenty by people who simply don't understand the question's domain enough to see that yes, that is a meaningful question with a compact, well-matched answer. And once closed, it seems no one really looks at 'reopen' requests, even after the question text improved.
It's frustrating when 9/10 of the questions aren't even deserving of an answer (at least that's my opinion) for the above reasons.
Obviously won't work for everyone, but it's a simple convention that's easy to grok and explain.
Case fatality ratio - but not restricted to any interval
Case fatality rate - but doesn't have a time or derivative (rate of change) component, which rates usually have
Case fatality risk - akin to probability, definitely between 0 and 1. That would be my choice.
It's shorter than the word "probability", and somewhat less frequently used, so it could be adopted for this purpose.
Edit to add: Though "accuracyRisk" does seem weird. Better than "accuracyUnitInterval" though maybe.
I don't know latin, but perun, perune, peruni?
Why yes.
For neologisms, 'tweening' comes to mind. (Think of the coefficient of a convex combination. 'Tweenness' feels just a little too long.) 'Fractile' from the stackexchange thread would also work.
Booleans have the same problem that we lack a plain English short word for "yes or no answer". I think we ought to start pushing 'bool' or 'boole' out of our jargon and into common English.
"Binary" is the term I use. E.g., "It's not a binary proposition" to call out a false dichotomy.
I don't mean to pick on you in particular abecedarius, but I find it amusing to be worried about signalling that irrational numbers are OK given the context is computing and all the numbers are rational anyway.
Represent it internally as either fixed or floating point and divide to convert in and out if needed.
With a nice type system you could even genericize the type over integer constants
So for me "perunage" sound very logical. "Un" means one in French (cent=100 and mille=1000).
> they actually represent numbers between 0-1
Not really. The often represents, for instance, a population of 100M, then 0 means 0, 1 (or 100%) means 100M and 1.2 (or 120%) means 120M (in case of population growth).
Or at very least an absolute normalized float
Calling it a "proportion" or "ratio" or "normalized" is like calling a variable "myinteger" or "myfloat". Your naming convention should be related to a variable's purpose, not its data type.
My latest example is, "I need to provide a flag to switch if this element is positive or negative. What do I name the flag?" (came up with simply: sign, or polarity)
But I messed up my own example. The one I was reaching for was a flag to set “clockwise or anti clockwise or neither”
I was looking for the terminology for clockwiseness
(evenp x) would return true if x was even.
So, "positivep". Though, yeah, that would be the name for a function that checks whether the argument was positive, not a flag.
ratio
saturated (if something is clamped to 0-1)
normalized (if it is scaled down using a max value) function FuncName(float AccuracySOMETHING)
to function FuncName([0...1] accuracy)As for which languages allow it. I'm not sure for floats, but Pascal let you do it for ints for sure. https://wiki.freepascal.org/subrange_types
https://en.wikipedia.org/wiki/Fraction#Proper_and_improper_f...
Otherwise you just want the mantissa stored as an int or byte[] until you need it to be converted to a floating point number.
What I do wish the languages I used had support for, is number types that the user could clamp to a specific range. It would be nice to have my code throw an error if some function resulted in clipped audio, for example. I mean, without the programmer writing any extra code, of course.
I don't think it really helps for the interval 0 to 1, but rather for the interval 0 to 0.000000000000000000000000000000000001 or whatever. It doesn't give you more significant digits, but rather a gradual degradation of significant digits as they get used for exponents.
Subnormal numbers are a bit controversial because of their relative utility vs. added complexity to implement them, especially in hardware.
Because chances are, I am going to be multiplying other floats by this number. And the performance penalty (not to mention the maintenance penalty) of converting back-and-forth between whatever you choose and floats will probably out-weigh the gains of storing it efficiently.
That said something like a uint would probably be most efficient if you did care. At that point, allignment issues also start cropping up performance wise.
Case in point: most software volume controls allow to specify the output volume (or rather, control the attenuation) using the full uint16 range. In this case, the entire volume range is expressed from 0x0000 to 0xFFFF. But in practice, this is just an amplification (multiplier) value between 0 and 1.
function FuncName(Bound<float, 0, 1> Accuracy)
...or if it doesn't function FuncName(BoundFloat0_1 Accuracy)
...or if it's dynamically typed function FuncName(AccuracyBoundFloat0_1)
...or if mentioning the bounds explicitely is too verbose/YAGNI for your taste function FuncName(UnitIntervalFloat Accuracy)"Proportion of Unity" "Proportion of Unity, Normalized". "P(er) Un" or "Perunage" contracted.
Short, doesn't clash hard with other meanings, is its own mnemonic.
AccuracyPun would be accuracy as a proportion of one. femPop might be 8000, but femPopPun would have to be [0,1].
Enter a fractional-unit-scalar value for the bias parameter
Enter a fractional-unit-scalar value for probability p0
pls no
But actually there's two "natural" hardware implementations for this. First is like floating point with no sign bits (mantissa is positive or zero, exponent is negative). The other is fixed point, basically re-interpreting unsigned ints as being implicitly divided by 0xfff...f -- both have advantages and drawbacks. And then comes the operations. Multiplication is the only closed operation -- addition, subtraction and division need special cases: should they be clamped, or wrap around? Both, probably -- wrapping is useful for trig functions, for example.
https://en.wikipedia.org/wiki/Parts-per_notation#Uno
I'm glad it never caught on.
Modoverflow strikes again
Example: FractionInclusive
subtype Probability is Float range 0.0 .. 1.0;
Piddling: amounting to very little; trifling; negligible
But in the code I'd probably use X_range depending on what 0..1 represents
edit: but I guess it is wrong, because % is ambiguous - it can mean fraction, it can mean growth
As 0% and 100% aren't floats (they're more like formatted values), seeing AccuracyPercent in the question had me thinking there was nothing more accurate.
You're still raising valid point with the ambiguity - if I were to see a variable named `population_percentage = 0.01` I'd still need to ask the author if the intended value here is 1 or 0.01, which I'd say disqualifies this naming.
Edit: also, put it into typename, not into argname.
function FuncName(float AccuracyBoolean)
function FuncName(float BoolAccuracy)
function FuncName(float IsAccurate)
Out of the answers there I like AccuracyNormalized best.
That immediately conveys (to me at least) what it is and what its magnitude will be bounded by.
Or...if you were writing Java or Swift
NonNegativeMagnitudelessFractionalQuantity
The takeaway is words are mostly a leaky abstraction, imperfect model for math concepts.
But I guess if you're a clever programmer you could call it a ThielAccuracy, or ThielRatio
But I guess a number that's always between 0 and 1 is an integer reciprocal. But again that's probably getting too deep for this.
I guess another way is UnitIntervalPoint or ProperFraction
I guess in Java we don't have to choose
FractionalPartRatioForAccuracyNormalized hehehe
I suppose we could make up a word
bition, or bitum
anabit or cobit - analog bit (continuous on 0 to 1)
proratio - proper ratio
Making up a word seems easier than the rest because it's more concise. :)
Programmers who think like this frighten me a lot. Those parameter names are not self explanatory at all, and cannot be assumed readily understood by developers picking up the code.
If you think “this is obvious” you need to add “to me” on the end, and “not necessarily to other people.”
This can go off the rails when people start making braindead claims that code should be self-documenting and need for comments or docstrings indicates poor code. But it can also just lead to bad documentation where you think a word is clear enough and you don’t realize others will cone into that segment of code with totally different use cases or contexts in mind, assumptions about the code’s usage constraints, different levels of skill and experience, different levels of comfort with the natural language that comments are written in.
Over-communicating within documentation is a hugely beneficial thing. It only costs a small amount of hassle for the person writing it and a small amount of hassle dealing with the eyesore of it for people already familiar, but it saves so much cognitive load for everyone else.
The main downside is keeping it up to date, but the false adage that wrong documentation is worse than no documentation is no excuse.
literally copy/pasted from wikipedia:
> A probability is a way of assigning every event a value between zero and one,
Ex. 50% of 12 marbles is 6 (*.5, 50%).
But just looking at all the different answers in the comments here means there's no consensus on a "right" way. Hence bike shedding. A decent code base should be consistent so it can focus on more important things.
That’s not a percentage. A percentage is between 0 and 100.
A doubling expressed as a percentage of a given baseline would be 200%; economic growth during a recession is typically expressed by a negative percentage.
Percent is a fancy way to 0.01, just as ‘dozen’ is a fancy way to say 12.
Percent has some strong norms around its usage (no-one buys 1200% eggs at the supermarket) but you can’t ignore the mathematical meaning.
In both cases, if someone used them as a type name, conversion to floats should involve multiplying by the unit.
https://en.wikipedia.org/wiki/Unit_interval#:~:text=In%20mat...
If you google accuracy, you'll get the noun. If you use a made up term, it'll probably return useless results.
Unit Interval Value is nice but still a bit cumbersome. I mean if we all agreed right now it were called a "poog" then we could just say poog.
typedef float UnitInterval;
void do_something_accurately(UnitInterval accuracy);I don't know much about C (? I assume that's what this is), but in other languages you can even build a wrapper type and enforce invariants in construction if really necessary.
Of course, all that ceremony only makes sense if this is really a type you use multiple times. Otherwise I wouldn't bother.
Just as we say an integer is a member of the set called the integers.
We say our "X" (the word we are looking for) is a member of the set called the closed unit interval.
(NB: "In real life" I would never "correct" someone for calling it "UnitInterval", it's good enough -- but given this is a pure discussion of semantics...)
typedef float UnitIntervalValue;
void do_something_accurately(UnitIntervalValue accuracy);
FTFYUnitIntervalValue would be the type name for the thing we are interested in.
Values of that type should of course have descriptive names.