Comments (2)
here's a test for trying out hex float literals in C99
#include <stdio.h>
#include <stdint.h>
int main() {
float f = 0x1f.0fp-4f;
uint32_t bits = *(int *)&f;
for (int i = 31; i >= 0; i--) {
if (i == 30 || i == 22) printf(" ");
printf("%d", (bits >> i) & 1);
}
printf("\n");
return 0;
}
$ gcc -std=c99 -Wall -Werror -Wpedantic a.c && ./a.out && rm a.out
0 01111111 11110000111100000000000
from zig.
[<radix>]<whole_number>[.<fraction>][<exponent_designtator>[<sign>]<exponent>]
radix
can be 0x
for hex, 0o
for octal, or 0b
for binary. In hex, the digits a-f
are case insensitive.
if either the fraction
or exponent
are given, then it is a float literal. otherwise, it's an integer literal.
the whole_number
and the fraction
are interpreted in the radix specified. the exponent
is always specified in base 10.
exponent_designator
is e
or E
for base 2, 8, and 10, and p
or P
for base 16.
sign
is +
or -
.
the significance of the exponent is 10^exp
for base 10 floats and 2^exp
for base 2, 8, and 16 floats. This means that 0x1p4
is 0x10
not 0x10000
.
This is very similar to the C99 syntax. It is more flexible in these ways:
- octal literals start with
0o
instead of just0
. - binary literals exist.
- octal and binary float literals exist.
- the exponent is not required for hex float literals.
I don't know about compliance with the IEEE 754-2008 standard; I can't find a copy of it on the internet.
from zig.
Related Issues (20)
- DynamicBitSetUnmanaged: .setAll() incorrectly sets all bits, or .iterator incorrectly traverses bits outside the bit_length. HOT 4
- C translation issue with downcasting pointer HOT 3
- Inefficient code generation of `@mod` and `@divFloor` HOT 4
- Improve `std.StaticStringMap.initComptime` HOT 6
- Support more hash algorithms in the package manager HOT 1
- build system caching run step false negatives regression HOT 1
- Memory leaks or not? HOT 2
- Incorrect @wasmMemoryGrow codegen for wasm64 target
- `std.options.crypto_always_getrandom` ignores overridden `std.options.cryptoRandomSeed` HOT 2
- `standalone_test_cases.stack_iterator` tests fail on Gentoo Linux x86_64
- Missing optional for lpName param on std.os.windows.kernel32.CreateEventExW HOT 1
- failed assertion in `writeManifest` consecutively using `zig build run` HOT 1
- Missing null terminator on various kernel32 signatures
- C interop: expected type `bool` found `c_int` HOT 6
- Const pointer with large array size doesn't throw any compiler error
- `readPackedIntBig` reads from end of array
- BoundedArray segfaults for items larger than stack HOT 1
- Compiler gets stuck in Infinite (so far) loop HOT 4
- Cannot directly access method of pointer to struct from HashMap's iterator HOT 4
- LLVM Basic Block has no termintor error when calling `@errorName` with `@as(error{}, undefined)`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zig.