wxMaxima
Loading...
Searching...
No Matches
Functions
DigitGrouping.cpp File Reference

Defines where a number gets its digit-group gaps, see DigitGrouping.h. More...

#include "DigitGrouping.h"
#include <algorithm>
#include <clocale>
#include <cmath>
Include dependency graph for DigitGrouping.cpp:

Functions

int wxm::DigitGroupGapWidth (double fontSize)
 How wide a digit-group gap is, in pixels, for text of the given font size.
 
int wxm::LocaleDigitGroupSize ()
 How many digits a group has: what the C library's LC_NUMERIC locale says, if that is 3 or 4, otherwise 3.
 
std::vector< size_t > wxm::DigitGroupGaps (const wxString &number, size_t minDigits, size_t groupSize=3)
 The indices into number before which a digit-group gap is drawn, ascending.
 
std::vector< std::vector< size_t > > wxm::DigitGroupGapsInTokens (const std::vector< std::pair< wxString, bool > > &tokens, size_t minDigits, size_t groupSize=3)
 DigitGroupGaps() for code, where a number may span several tokens.
 

Detailed Description

Defines where a number gets its digit-group gaps, see DigitGrouping.h.

Function Documentation

◆ DigitGroupGaps()

std::vector< size_t > wxm::DigitGroupGaps ( const wxString &  number,
size_t  minDigits,
size_t  groupSize = 3 
)

The indices into number before which a digit-group gap is drawn, ascending.

number is a number as Maxima prints it, optionally preceded by a sign (including the unicode minus sign MathParser turns "-" into): "12345", "−3.14159", "1.234567b10", "6.02214076e23".

  • The digits before the decimal point are grouped from the right, the ones after it from the decimal point on, so the groups always line up with the point: "12 345.678 9".
  • Nothing is grouped unless the mantissa (the digits before and after the point together) has at least minDigits digits, so a short number like a year (2026) stays as it is by default.
  • An exponent ("e-10", "b25") and anything else after the mantissa is never grouped, nor is anything that doesn't start with a (signed) digit or point.

◆ DigitGroupGapsInTokens()

std::vector< std::vector< size_t > > wxm::DigitGroupGapsInTokens ( const std::vector< std::pair< wxString, bool > > &  tokens,
size_t  minDigits,
size_t  groupSize = 3 
)

DigitGroupGaps() for code, where a number may span several tokens.

MaximaTokenizer makes "3.14159" three tokens, "3", "." and "14159", and ".5" two. Grouped one token at a time, the digits after the point would be grouped from the right, like an integer's; this joins such tokens up into the number they form first.

tokens holds each token's text and whether it is a number token. The result has one entry per token: the gaps inside it, as indices into that token's own text. A gap never falls on a token boundary, so each gap belongs to exactly one token.

◆ DigitGroupGapWidth()

int wxm::DigitGroupGapWidth ( double  fontSize)

How wide a digit-group gap is, in pixels, for text of the given font size.

5/24 of an em: halfway between a typographic thin space (a sixth of an em, what the gap started out as, which made the groups a bit hard to tell apart) and a quarter of an em (what it was widened to next, which felt a little too wide). Output (TextCell) and code (EditorCell) both use this, so that a number looks the same in either. Never less than one pixel, so the gap doesn't vanish at tiny zoom levels.

◆ LocaleDigitGroupSize()

int wxm::LocaleDigitGroupSize ( )

How many digits a group has: what the C library's LC_NUMERIC locale says, if that is 3 or 4, otherwise 3.

Locales with irregular grouping (India's 12,34,56,789) get groups of their first size throughout, which is what LongNumberCell::BreakUp() has always done, too.