# What's the best way to determine which suffix to use?

• I'm certain this isn't it...

``````        char temp[32];
int len = snprintf(temp, sizeof(temp), "%lu", number);
char unit = len < 4 ? ' ' : len < 7 ? 'K' : len < 10 ? 'M' : 'G';
``````

(Language is C.)

• It's a creative way to get an approximation for the base-10 logarithm (plus 1), though.

• The whole concept behind what the function does is somewhat WTFy.

It 'compacts' a number by truncating (not rounding) it to 3SF and replacing the decimal point with the prefix. So, e.g.:

• 987-> 987
• 9876 -> 9K87 (yup, not 9K88)
• 9876543 -> 9M87 (ditto)

Given this deals with bandwidth speeds and data transferred, why it was 10^3 based instead of 2^10 is another curiosity.

• Given this deals with bandwidth speeds and data transferred, why it was 10^3 based instead of 2^10 is another curiosity proof that the author doesn't know how to maths.

FTFY

• Oh, the author (an ex-linemanager who is no longer with us) knew exactly what he was doing - this just isn't a shining example of his work.

Just checked svn blame to make sure it was who I thought it was. It was checked in ~7 years ago, 2 weeks after I joined the company as it happens...

• ```len -= unit == ' '? 0: unit == 'K'? 3: unit == 'M'? 6: 9; temp[len++] = unit; temp[len] = '\0';```

We likes it!

• Given this deals with bandwidth speeds and data transferred, why it was 10^3 based instead of 2^10 is another curiosity.

My ISP measures my data consumption in GB, not GiB. Does yours not?

• My ISP measures my data consumption in GB, not GiB

And this is why we need this -bi bullshit...

• My ISP measures my data consumption in GB, not GiB. Does yours not?

Like Discourse, there is lots of consistency within the company between GB and GiB...

• I recently ripped out code that did something like this (if/elseif chain) and replaced with printf("%'llu"). Output:
1,234,567,890 .

• It 'compacts' a number by truncating (not rounding) it to 3SF and replacing the decimal point with the prefix. So, e.g.:

987-> 987
9876 -> 9K87 (yup, not 9K88)
9876543 -> 9M87 (ditto)

That's an electronics shorthand form, by the way; your nuff-nuff ex-linemanager didn't invent it.

• That's an electronics shorthand form

Ah. That does make some sense then...

• That's an electronics shorthand form

I noticed the author of that spells "colour" with a U, so maybe that shorthand is a British thing. I'm an EE with over 25 years of experience; although I may have seen that before, it's certainly not something I've encountered often enough to immediately recognize what it means.

• Is Y2K38

• Y2038
• Y2380
• Y200038
• 76 KiB

• No.

• maybe that shorthand is a British thing

I first encountered it in Electronics Australia and Electronics Today International magazines as a teenager in the 1970s, and it is indeed part of British Standard 1852.

• 76 KiB

this, absolutley. no ambiguity

• I noticed the author of that spells "colour" with a U, so maybe that shorthand is a British thing. I'm an EE with over 25 years of experience; although I may have seen that before, it's certainly not something I've encountered often enough to immediately recognize what it means.

It's quite useful when working with resistors, where you often have quite a large range of magnitudes of values in use in the same circuit. I don't recall seeing it used for much else, though I suppose it would make sense for capacitances too.

• The main advantage of something like 4k7 over something like 4.7k is that it's far less likely to be misinterpreted after a few generations of reproduction on photocopiers, fax machines and so forth. And yes, I have seen circuits with all the capacitors specified like 2μ7 and 56n and so on.

• Just always report in bits, let people screw up units on their own.

• Just always report in bits, let people screw up units on their own.

Just hope and prey they use the same value of `CHAR_BITS` that you are...

``````#define CHAR_MIN (-128)/0
``````

that cannot be right....

• That's not a divide sign. That's `-128` or `0` (depending on whether unadorned `char` is signed or unsigned)

Quite why they've documented it that way I dunno.

• That's not a divide sign. That's `-128` or `0` (depending on whether unadorned `char` is signed or unsigned)

Quite ambigious.

`-128/0`

versus

`-128`
OR
`0`

Much clearer.

• ....

really....

it's a weird way to document....

• ....

really....

it's a weird way to document....

I'd go so far as to say it's the wrong way to document it.

• I'd go so far as to say it's the wrong way to document it.

@chubertdev said:
I'd go so far as to say it's the wrong way to document it.

DQFDT

• Quite ambigious.

-128/0

In Progress, that's how you specify a display format for a Boolean. format "yes/no" controls how the field will be displayed.

• In Progress, that's how you specify a display format for a Boolean. format "yes/no" controls how the field will be displayed.

Not exactly the name that I would use for that.

• I didn't name the language, but you can use "OpenEdge ABL" instead, if you want, because that's what they changed it to.

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.