@@ -66,29 +66,26 @@ static void dd_update_decision_maker_tag(ddtrace_root_span_data *root_span,
6666static void dd_update_knuth_sampling_rate_tag (ddtrace_root_span_data * root_span , double sample_rate ) {
6767 zend_array * meta = ddtrace_property_array (& root_span -> property_meta );
6868
69- // Round to 6 decimal places at integer level to avoid IEEE 754 precision issues,
70- // then format with fixed-point notation (never scientific notation).
71- double rounded = floor (sample_rate * 1e6 + 0.5 ) / 1e6 ;
7269 char buf [32 ];
73- snprintf (buf , sizeof (buf ), "%.6f" , rounded );
70+ int is_negative ;
71+ size_t len ;
72+ php_conv_fp ('F' , sample_rate , false, 6 , '.' , & is_negative , buf , & len ); // F for fixed point vs scientific notation
7473
75- // Strip trailing zeros and optional decimal point
76- size_t len = strlen (buf );
7774 while (len > 1 && buf [len - 1 ] == '0' ) {
78- buf [ -- len ] = '\0' ;
75+ -- len ;
7976 }
8077 if (len > 1 && buf [len - 1 ] == '.' ) {
81- buf [ -- len ] = '\0' ;
78+ -- len ;
8279 }
8380
8481 // Skip update if already set to the same value
8582 zval * existing = zend_hash_str_find (meta , ZEND_STRL ("_dd.p.ksr" ));
86- if (existing && Z_TYPE_P (existing ) == IS_STRING && strcmp ( Z_STRVAL_P (existing ), buf ) == 0 ) {
83+ if (existing && Z_TYPE_P (existing ) == IS_STRING && zend_string_equals_cstr ( Z_STR_P (existing ), buf , len ) == 0 ) {
8784 return ;
8885 }
8986
9087 zval ksr ;
91- ZVAL_STRING (& ksr , buf );
88+ ZVAL_STRINGL (& ksr , buf , len );
9289 zend_hash_str_update (meta , ZEND_STRL ("_dd.p.ksr" ), & ksr );
9390 zend_hash_str_add_empty_element (ddtrace_property_array (& root_span -> property_propagated_tags ), ZEND_STRL ("_dd.p.ksr" ));
9491}
0 commit comments