https://github.com/shader-slang/slang
Revision acf26257b74ca5446fd5a0390a29723dc25ef2a3 authored by Tim Foley on 19 December 2017, 19:49:36 UTC, committed by GitHub on 19 December 2017, 19:49:36 UTC
There was a bug that arose in the context of Falcor, because:

- Slang uses `sprintf` to format floating-point values when outputting HLSL/GLSL source

- Falcor (or a library it uses) does the equivalent of `setlocale(LC_ALL, "")` to set the global locale for the process based on the user's environment variables

This led to a floating-point literal of `0.5` getting printed as `0,5f`, with a comma for the decimal point. This then gets consumed by `glslang` which (luckily for us) complains that `5f` is not a valid floating-point literal in their language (since it has neither decimal point nor exponent).

The most expedient fix in this case was to switch from using C `sprintf` for formatting floating-point numbers over to using the C++ `<stdio>` implementation, which allows the locale to be set per-stream so that we don't have to rely on (or potentially disrupt) the global locale set by an application using Slang.

Longer term if we have the time/resources to do the Right Thing, it would be best to implement our own printing logic for floating-point numbers, since we would eventually need/want to support arbitrary-precision numbers for literals.
1 parent 393e25f
History
Tip revision: acf26257b74ca5446fd5a0390a29723dc25ef2a3 authored by Tim Foley on 19 December 2017, 19:49:36 UTC
Fix floating-point literal emit to be locale-independent. (#315)
Tip revision: acf2625
File Mode Size
build
docs
examples
external
source
tests
tools
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 398 bytes
.gitmodules -rw-r--r-- 107 bytes
.travis.yml -rw-r--r-- 1.6 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
Makefile -rw-r--r-- 6.3 KB
README.md -rw-r--r-- 6.2 KB
appveyor.yml -rw-r--r-- 3.5 KB
slang.h -rw-r--r-- 39.1 KB
slang.sln -rw-r--r-- 9.1 KB
test.bat -rw-r--r-- 1.4 KB

README.md

back to top