question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extended Numeric Literals

See original GitHub issue

Search Terms

  • extended-numeric-literals
  • extended numeric literals

Suggestion

Support tc39/proposal-extended-numeric-literals (Stage 1)

Use Cases

For represent lengths in pixels, inches, degrees, radians, seconds and other units without calling specifically conversion methods in runtime (if this possible).

const time = 100s // transforms to `100,000` ms
const angle = 180° // transforms to `3.1415926536` radians

Examples

function deg(value: number): number {
   return value * (Math.PI / 180);
}

function °(value: number): number {
   return deg(value);
}

function _f32(value: number): number {
  return Math.fround(value);
}

function _u32(value: number): number {
  return value >>> 0;
}

function px(value: number): string {
  return `${ value }px`;
}

var angle = 30deg; // transforms to `0.5235987756`
const angle2 = 180°; // transforms to `pi` (`3.1415926536`)
let count = 1_000_000_u32;
var float32 = 1.0_f32;
canvas.style.width = 512px; // transforms to "512px" string

Also related to #15096

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
MaxGraeycommented, Jun 10, 2018

This is already used with the arrival of BigInt. And with success has taken hold in such modern languages ​​like Rust, Ruby, Swift

0reactions
Shinigami92commented, Jun 10, 2018

If this will land in JavaScript it should support by Typescript as well, isn’t it?

@MaxGraey Yes it is

Read more comments on GitHub >

github_iconTop Results From Across the Web

tc39/proposal-extended-numeric-literals - GitHub
Numeric literal suffixes live in a parallel lexical scope. Entries can be created in the scope with a SuffixDeclaration , of the form...
Read more >
Extended Numeric Literals - TC39
This document is a Stage 1 draft specification for extended numeric literals in JavaScript. For a high-level overview of the design, ...
Read more >
Integer literal - cppreference.com
The type of the integer literal is the first type in which the value can fit, from the list of types which depends...
Read more >
Numeric Literals - Embedded.com
0x3FL has type (signed)long int .An integer literal suffix may combine U with either L or LL (in either upperor lower case and...
Read more >
Underscores in Numeric Literals
Underscores in Numeric Literals. In Java SE 7 and later, any number of underscore characters ( _ ) can appear anywhere between digits...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found