# Loss of double precision when multiplying | NVidia

Good afternoon, everyone!

Please, tell me if the community knows anything about the strange behavior of NVidia graphics cards in relation to the product of two double precision numbers in OpenGL computational shader?

Here’s the deal - I created a computational shader that processes geodetic data, and quickly realized that float precision is not enough for most trigonometric operations.

I used the `GL_ARB_gpu_shader_fp64` extension to enable support for double numbers, and implemented my sine, cosine, and arctangent functions with double precision using Taylor expansions and the Padé polynomial.

However, nothing has changed in my calculations, even though I am absolutely sure that my functions are correct. I did some debugging of the shader to find out what the problem was and discovered that the product of two different double numbers is rounded to float, even though the result of the product is of type double.

Especially interesting is the fact that I encounter this behavior only on NVidia graphics cards (RTX 4070 and 4080), but on AMD graphics cards (RX 580, RX 6700) everything is correct (for the same code).

I implemented a test program on Qt 5.15 comparing the results of sine calculation for some data set on CPU using `<math.h>` library and the results of calculation by my function inside the shader on GPU. This program outputs the original data set for sine calculation, as well as the sets of processed (sine) data obtained on CPU and GPU, then compares the results and outputs the maximum and average calculation error (relative to math.h).

I’ll attach the shader code with some comments, and say that the control program is exactly right.

Thank you for any help!

P.S. It is worth noting that I have tried a lot of things. I tried splitting the data into small parts, checking intermediate calculations, using the “precise” modifier, but EVERYTHING points to the fact that the NVidia compiler apparently optimizes the product of two double numbers to float precision.

P.P.S. I apologize for the long table in the code. I have shortened it considerably, but it is still large. Without it, I’m afraid nobody will believe me that my algorithm works correctly at all.

``````#version 430 core

layout (local_size_x = 1024, local_size_y = 1, local_size_z = 1) in;

layout (std430, binding = 0) buffer debugInfoBH {
double debugInfo[];
};

double PI = 3.141592653589793238462643383279lf;
double TAU = 6.283185307179586477lf;

// =============================================
double DsinTaylorTable[][6] =
{
{0.000000000000000005lf, 0.999999999999997002lf, 0.000000000000843494lf, -0.166666666787488260lf, 0.000000009230097997lf, 0.008333016025534760lf},
{0.000000000000010030lf, 0.999999999997764344lf, 0.000000000204954024lf, -0.166666676452553619lf, 0.000000249197463313lf, 0.008330477708129645lf},
{0.000000000000358366lf, 0.999999999952088658lf, 0.000000002635343280lf, -0.166666742164831294lf, 0.000001153551389282lf, 0.008325401846515482lf},
{0.000000000003776854lf, 0.999999999639332060lf, 0.000000014170424681lf, -0.166666956641516290lf, 0.000003164766486946lf, 0.008317789986848892lf},
{0.000000000021928181lf, 0.999999998371296939lf, 0.000000049771323972lf, -0.166667458840684707lf, 0.000006724642939041lf, 0.008307644447776066lf},
{0.000000000089306340lf, 0.999999994572779105lf, 0.000000135697713448lf, -0.166668433820118034lf, 0.000012274037160153lf, 0.008294968319726490lf},
{0.000000000287429289lf, 0.999999985219709231lf, 0.000000312706413340lf, -0.166670112549209631lf, 0.000020252592888140lf, 0.008279765463971562lf},
{0.000000000782214904lf, 0.999999965139087954lf, 0.000000639227861574lf, -0.166672771674073517lf, 0.000031098472829729lf, 0.008262040511448420lf},
{0.000000001877392519lf, 0.999999926172204900lf, 0.000001194515572567lf, -0.166676733236006042lf, 0.000045248090983012lf, 0.008241798861349308lf},
{0.000000004086756766lf, 0.999999856202947845lf, 0.000002081763728415lf, -0.166682364343480105lf, 0.000063135845759211lf, 0.008219046679476929lf},
{0.000000008228016685lf, 0.999999738053285347lf, 0.000003431188072986lf, -0.166690076797882808lf, 0.000085193854025860lf, 0.008193790896366288lf},
{0.000000015540929932lf, 0.999999548248305725lf, 0.000005403065311396lf, -0.166700326673235255lf, 0.000111851686193081lf, 0.008166039205173579lf},
{0.000000027832342708lf, 0.999999255653487462lf, 0.000008190726251800lf, -0.166713613850164782lf, 0.000143536102464266lf, 0.008135800059332779lf},
{0.000000047650676460lf, 0.999998819987153231lf, 0.000012023497967070lf, -0.166730481504427319lf, 0.000180670790371998lf, 0.008103082669980638lf},
{0.000000078492317312lf, 0.999998190211353277lf, 0.000017169590296906lf, -0.166751515550308815lf, 0.000223676103719489lf, 0.008067897003150897lf},
{0.000000125042270538lf, 0.999997302804695565lf, 0.000023938922058653lf, -0.166777344039261893lf, 0.000272968803047278lf, 0.008030253776738525lf},
{0.000000193451339003lf, 0.999996079920921543lf, 0.000032685882387307lf, -0.166808636514164527lf, 0.000328961797744306lf, 0.007990164457234942lf},
{0.000000291651979123lf, 0.999994427437293054lf, 0.000043812022680112lf, -0.166846103319614691lf, 0.000392063889921787lf, 0.007947641256235224lf},
{0.000000429714866967lf, 0.999992232897125688lf, 0.000057768674681352lf, -0.166890494868704720lf, 0.000462679520167614lf, 0.007902697126718327lf},
{0.000000620248090388lf, 0.999989363351067806lf, 0.000075059490306173lf, -0.166942600866746477lf, 0.000541208515298265lf, 0.007855345759101486lf},
{0.000000878840744067lf, 0.999985663101975564lf, 0.000096242898870003lf, -0.167003249492446715lf, 0.000628045838224334lf, 0.007805601577069981lf},
{0.000001224552577062lf, 0.999980951358492187lf, 0.000121934477460228lf, -0.167073306537060401lf, 0.000723581340045019lf, 0.007753479733183538lf},
{0.000001680451189645lf, 0.999975019802682774lf, 0.000152809230264006lf, -0.167153674502075550lf, 0.000828199514485871lf, 0.007698996104260723lf},
{0.000002274198133700lf, 0.999967630077316483lf, 0.000189603772741548lf, -0.167245291656012707lf, 0.000942279254793323lf, 0.007642167286542700lf},
{0.000003038685110535lf, 0.999958511198620337lf, 0.000233118416619688lf, -0.167349131050946953lf, 0.001066193613198381lf, 0.007583010590637860lf},
{0.000004012721296132lf, 0.999947356900559581lf, 0.000284219151764770lf, -0.167466199499387874lf, 0.001200309563060838lf, 0.007521544036248839lf},
{0.000005241772663811lf, 0.999933822916915238lf, 0.000343839521083300lf, -0.167597536512179096lf, 0.001344987763804342lf, 0.007457786346683542lf},
{0.000006778753990633lf, 0.999917524207646902lf, 0.000412982384693034lf, -0.167744213198104869lf, 0.001500582328751474lf, 0.007391756943151848lf},
{0.000008684874062914lf, 0.999898032136234183lf, 0.000492721569702398lf, -0.167907331125916381lf, 0.001667440595966789lf, 0.007323475938849712lf},
{0.000011030534409651lf, 0.999874871604883086lf, 0.000584203402036659lf, -0.168088021149515932lf, 0.001845902902214550lf, 0.007252964132832497lf},
{0.000013896281704118lf, 0.999847518154685977lf, 0.000688648116851764lf, -0.168287442197061932lf, 0.002036302360136726lf, 0.007180243003679382lf},
{0.000017373813782140lf, 0.999815395037990773lf, 0.000807351144184593lf, -0.168506780024781394lf, 0.002238964638755291lf, 0.007105334702950769lf},
{0.000021567039027337lf, 0.999777870270425750lf, 0.000941684266595522lf, -0.168747245936301943lf, 0.002454207747401765lf, 0.007028262048440715lf},
{0.000026593188674540lf, 0.999734253670176098lf, 0.001093096645674418lf, -0.169010075468336629lf, 0.002682341823175297lf, 0.006949048517226402lf},
{0.000032583981376899lf, 0.999683793892279571lf, 0.001263115714394331lf, -0.169296527043580614lf, 0.002923668922029405lf, 0.006867718238516798lf},
{0.000039686839174990lf, 0.999625675465844354lf, 0.001453347932418469lf, -0.169607880591699012lf, 0.003178482813585709lf, 0.006784295986302660lf},
{0.000048066153793491lf, 0.999559015842239162lf, 0.001665479401584957lf, -0.169945436139308653lf, 0.003447068779771773lf, 0.006698807171810145lf},
{0.000057904601983405lf, 0.999482862462433452lf, 0.001901276338919511lf, -0.170310512369878320lf, 0.003729703417378397lf, 0.006611277835760293lf},
{0.000069404508404758lf, 0.999396189851780137lf, 0.002162585404653417lf, -0.170704445154492013lf, 0.004026654444630167lf, 0.006521734640436783lf},
{0.000082789254330806lf, 0.999297896750651837lf, 0.002451333882852347lf, -0.171128586054441839lf, 0.004338180511861512lf, 0.006430204861564333lf},
{0.000098304730238863lf, 0.999186803289433767lf, 0.002769529712394914lf, -0.171584300796636724lf, 0.004664531016388702lf, 0.006336716380000258lf},
{0.000116220830122082lf, 0.999061648216471587lf, 0.003119261366174741lf, -0.172072967722832371lf, 0.005005945921666546lf, 0.006241297673241684lf},
{0.000136832985148660lf, 0.998921086187649632lf, 0.003502697576534430lf, -0.172595976213707814lf, 0.005362655580816934lf, 0.006143977806751034lf},
{0.000160463734056759lf, 0.998763685126346501lf, 0.003922086905081834lf, -0.173154725088832118lf, 0.005734880564614381lf, 0.006044786425102396lf},
{0.000187464327464859lf, 0.998587923662571320lf, 0.004379757155179798lf, -0.173750620983582793lf, 0.006122831494011917lf, 0.005943753742951513lf},
{0.000218216363048751lf, 0.998392188660132240lf, 0.004878114625540053lf, -0.174385076704094616lf, 0.006526708877289178lf, 0.005840910535832091lf},
{0.000253133448307574lf, 0.998174772840730640lf, 0.005419643203505242lf, -0.175059509561335508lf, 0.006946702951901938lf, 0.005736288130781283lf},
{0.000292662887435124lf, 0.997933872513892650lf, 0.006006903296740973lf, -0.175775339685421195lf, 0.007382993531111260lf, 0.005629918396797170lf},
{0.000337287388574525lf, 0.997667585421672887lf, 0.006642530602217644lf, -0.176533988321296631lf, 0.007835749855467686lf, 0.005521833735131145lf},
{0.000387526787531622lf, 0.997373908707065437lf, 0.007329234711504928lf, -0.177336876106927749lf, 0.008305130449224537lf, 0.005412067069418198lf},
{0.000443939783792424lf, 0.997050737015050093lf, 0.008069797551559621lf, -0.178185421335160465lf, 0.008791282981751938lf, 0.005300651835648033lf},
{0.000507125684481968lf, 0.996695860735184347lf, 0.008867071660339398lf, -0.179081038200418818lf, 0.009294344134021276lf, 0.005187621971980164lf},
{0.000577726151690938lf, 0.996306964394624628lf, 0.009723978296728109lf, -0.180025135031427058lf, 0.009814439470227945lf, 0.005073011908406005lf},
{0.000656426948378863lf, 0.995881625210413568lf, 0.010643505384419383lf, -0.181019112511152602lf, 0.010351683314617503lf, 0.004956856556261178lf},
{0.000743959677865891lf, 0.995417311809820626lf, 0.011628705289557340lf, -0.182064361885179604lf, 0.010906178633579143lf, 0.004839191297591166lf},
{0.000841103511716956lf, 0.994911383127463522lf, 0.012682692432097409lf, -0.183162263159733718lf, 0.011478016923067214lf, 0.004720051974373607lf},
{0.000948686900626328lf, 0.994361087487853013lf, 0.013808640731004129lf, -0.184314183290589073lf, 0.012067278101410114lf, 0.004599474877600485lf},
{0.001067589262715107lf, 0.993763561881925162lf, 0.015009780883568469lf, -0.185521474364099159lf, 0.012674030407563364lf, 0.004477496736223533lf},
{0.001198742643465311lf, 0.993115831446023112lf, 0.016289397479285039lf, -0.186785471771602513lf, 0.013298330304861262lf, 0.004354154705966241lf},
{0.001343133341331959lf, 0.992414809151676125lf, 0.017650825948891419lf, -0.188107492378461361lf, 0.013940222390319560lf, 0.004229486358005868lf},
{0.001501803492891640lf, 0.991657295714413634lf, 0.019097449349336659lf, -0.189488832689002740lf, 0.014599739309539141lf, 0.004103529667528892lf},
{0.001675852611219941lf, 0.990839979729702280lf, 0.020632694985605021lf, -0.190930767008634206lf, 0.015276901677258422lf, 0.003976323002163404lf},
{0.001866439071018910lf, 0.989959438043965911lf, 0.022260030870485781lf, -0.192434545604417528lf, 0.015971718003599842lf, 0.003847905110291949lf},
{0.002074781533850323lf, 0.989012136368475625lf, 0.023982962023545717lf, -0.194001392865385869lf, 0.016684184626053356lf, 0.003718315109248406lf},
{0.002302160306697221lf, 0.987994430143749325lf, 0.025805026610715764lf, -0.195632505463898376lf, 0.017414285647237782lf, 0.003587592473402461lf},
{0.002549918626903236lf, 0.986902565661896380lf, 0.027729791926076747lf, -0.197329050519327559lf, 0.018161992878478164lf, 0.003455777022135324lf},
{0.002819463866422789lf, 0.985732681454177806lf, 0.029760850217584872lf, -0.199092163765381081lf, 0.018927265789234794lf, 0.003322908907710385lf},
{0.003112268648177495lf, 0.984480809950831648lf, 0.031901814358640188lf, -0.200922947722361883lf, 0.019710051462417798lf, 0.003189028603042414lf},
{0.003429871867187073lf, 0.983142879420013438lf, 0.034156313367569524lf, -0.202822469875671790lf, 0.020510284555617708lf, 0.003054176889369144lf},
{0.003773879609037023lf, 0.981714716192466974lf, 0.036527987777248722lf, -0.204791760861867317lf, 0.021327887268281023lf, 0.002918394843828895lf},
{0.004145965958140152lf, 0.980192047178318759lf, 0.039020484857256482lf, -0.206831812663576364lf, 0.022162769314856477lf, 0.002781723826948091lf},
{0.004547873688147741lf, 0.978570502682132082lf, 0.041637453691108550lf, -0.208943576814583920lf, 0.023014827903935834lf, 0.002644205470042434lf},
{0.004981414826787878lf, 0.976845619522110242lf, 0.044382540111281232lf, -0.211127962616396436lf, 0.023883947723410140lf, 0.002505881662535609lf},
{0.005448471087326934lf, 0.975012844459063777lf, 0.047259381494893893lf, -0.213385835367591037lf, 0.024770000931660058lf, 0.002366794539199356lf},
{0.005950994158788137lf, 0.973067537940491833lf, 0.050271601423071188lf, -0.215718014607255787lf, 0.025672847154796438lf, 0.002226986467318808lf},
{0.006491005846999964lf, 0.971004978164821231lf, 0.053422804207170549lf, -0.218125272373822399lf, 0.026592333489964488lf, 0.002086500033787012lf},
{0.007070598058516120lf, 0.968820365470577149lf, 0.056716569285205493lf, -0.220608331480591890lf, 0.027528294514722718lf, 0.001945378032132546lf},
{0.007691932619392328lf, 0.966508827054924247lf, 0.060156445491956062lf, -0.223167863809247441lf, 0.028480552302505090lf, 0.001803663449484191lf},
{0.008357240920805031lf, 0.964065422025723651lf, 0.063745945206406918lf, -0.225804488622644739lf, 0.029448916444172191lf, 0.001661399453476645lf},
{0.009068823383474534lf, 0.961485146790910350lf, 0.067488538380299140lf, -0.228518770898164747lf, 0.030433184075655088lf, 0.001518629379101229lf},
{0.009829048732852536lf, 0.958762940788667417lf, 0.071387646451739978lf, -0.231311219682906410lf, 0.031433139911692193lf, 0.001375396715505649lf},
{0.010640353077059211lf, 0.955893692561533115lf, 0.075446636147948012lf, -0.234182286471992240lf, 0.032448556285658153lf, 0.001231745092746756lf},
{0.011505238779561333lf, 0.952872246177210114lf, 0.079668813181369036lf, -0.237132363611247898lf, 0.033479193195479595lf, 0.001087718268500431lf},
{0.012426273118643361lf, 0.949693407998505990lf, 0.084057415843526953lf, -0.240161782725513417lf, 0.034524798355631686lf, 0.000943360114732555lf},
{0.013406086725739397lf, 0.946351953804439927lf, 0.088615608501126888lf, -0.243270813173829453lf, 0.035585107255205452lf, 0.000798714604335201lf},
{0.014447371794801100lf, 0.942842636264199729lf, 0.093346474999051146lf, -0.246459660532737324lf, 0.036659843222034472lf, 0.000653825797732042lf},
{0.015552880054898618lf, 0.939160192765222890lf, 0.098253011975039523lf, -0.249728465108915471lf, 0.037748717492865867lf, 0.000508737829457141lf},
{0.016725420498390958lf, 0.935299353596296901lf, 0.103338122090961881lf, -0.253077300482368373lf, 0.038851429289558918lf, 0.000363494894711133lf},
{0.017967856857061391lf, 0.931254850486177288lf, 0.108604607185733809lf, -0.256506172081368944lf, 0.039967665901291471lf, 0.000218141235898943lf},
{0.019283104818755996lf, 0.927021425497800755lf, 0.114055161355046897lf, -0.260015015790344917lf, 0.041097102772752067lf, 0.000072721129153116lf},
{0.020674128977179206lf, 0.922593840277764921lf, 0.119692363963208717lf, -0.263603696591883374lf, 0.042239403598292986lf, -0.000072721129153116lf},
{0.022143939507637551lf, 0.917966885660336795lf, 0.125518672592513925lf, -0.267272007244018117lf, 0.043394220422017057lf, -0.000218141235898943lf},
{0.023695588561691058lf, 0.913135391624799730lf, 0.131536415935681467lf, -0.271019666993943253lf, 0.044561193743768379lf, -0.000363494894711133lf},
{0.025332166373833204lf, 0.908094237604548438lf, 0.137747786637007485lf, -0.274846320329288685lf, 0.045739952630994715lf, -0.000508737829457141lf},
{0.027056797073492539lf, 0.902838363145878176lf, 0.144154834088003503lf, -0.278751535768070158lf, 0.046930114836446810lf, -0.000653825797732042lf},
{0.028872634195873048lf, 0.897362778913991632lf, 0.150759457183383433lf, -0.282734804688414110lf, 0.048131286921677174lf, -0.000798714604335201lf},
{0.030782855885326060lf, 0.891662578043282750lf, 0.157563397043384901lf, -0.286795540199138388lf, 0.049343064386298784lf, -0.000943360114732555lf},
{0.032790659785202597lf, 0.885732947828524964lf, 0.164568229708496661lf, -0.290933076052251993lf, 0.050565031802961416lf, -0.001087718268500431lf},
{0.034899257608348944lf, 0.879569181753119600lf, 0.171775358812773782lf, -0.295146665598418012lf, 0.051796762958000592lf, -0.001231745092746756lf},
{0.037111869382680018lf, 0.873166691850110532lf, 0.179186008242005562lf, -0.299435480786406749lf, 0.053037820997712572lf, -0.001375396715505649lf},
{0.039431717366513463lf, 0.866521021391206014lf, 0.186801214783103187lf, -0.303798611207541702lf, 0.054287758580205334lf, -0.001518629379101229lf},
{0.041862019628642666lf, 0.859627857898587533lf, 0.194621820771149590lf, -0.308235063186124758lf, 0.055546118032773817lf, -0.001661399453476645lf},
{0.044405983288408224lf, 0.852483046473811568lf, 0.202648466740645572lf, -0.312743758916803838lf, 0.056812431514744882lf, -0.001803663449484191lf},
{0.047066797411352002lf, 0.845082603437648183lf, 0.210881584087554669lf, -0.317323535649823796lf, 0.058086221185735587lf, -0.001945378032132546lf},
{0.049847625556333097lf, 0.837422730274222649lf, 0.219321387748838081lf, -0.321973144925080557lf, 0.059366999379265151lf, -0.002086500033787012lf},
{0.052751597970352504lf, 0.829499827872358320lf, 0.227967868906223808lf, -0.326691251855874110lf, 0.060654268781659706lf, -0.002226986467318808lf},
{0.055781803427652266lf, 0.821310511056549064lf, 0.236820787721035264lf, -0.331476434463233438lf, 0.061947522616185746lf, -0.002366794539199356lf},
{0.058941280710039012lf, 0.812851623399495793lf, 0.245879666106955996lf, -0.336327183061661039lf, 0.063246244832346366lf, -0.002505881662535609lf},
{0.062233009725744637lf, 0.804120252307703565lf, 0.255143780547669397lf, -0.341241899697122542lf, 0.064549910300272115lf, -0.002644205470042434lf},
{0.065659902264529224lf, 0.795113744371116038lf, 0.264612154966364532lf, -0.346218897638077339lf, 0.065857985010135511lf, -0.002781723826948091lf},
{0.069224792387135192lf, 0.785829720967342160lf, 0.274283553654143586lf, -0.351256400920325951lf, 0.067169926276516967lf, -0.002918394843828895lf},
{0.072930426447610386lf, 0.776266094110505955lf, 0.284156474264415759lf, -0.356352543946418465lf, 0.068485182947646855lf, -0.003054176889369144lf},
{0.076779452747455554lf, 0.766421082534321840lf, 0.294229140880395312lf, -0.361505371140344756lf, 0.069803195619446645lf, -0.003189028603042414lf},
{0.080774410820971476lf, 0.756293227998504181lf, 0.304499497162862287lf, -0.366712836658199204lf, 0.071123396854289950lf, -0.003322908907710385lf},
{0.084917720351658343lf, 0.745881411807165051lf, 0.314965199585365729lf, -0.371972804155483727lf, 0.072445211404401896lf, -0.003455777022135324lf},
{0.089211669719959530lf, 0.735184871527385875lf, 0.325623610764080862lf, -0.377283046611686934lf, 0.073768056439813809lf, -0.003587592473402461lf},
{0.093658404183129984lf, 0.724203217895687423lf, 0.336471792889549703lf, -0.382641246212745312lf, 0.075091341780786969lf, -0.003718315109248406lf},
{0.098259913688499845lf, 0.712936451899674584lf, 0.347506501267542289lf, -0.388044994291967482lf, 0.076414470134618898lf, -0.003847905110291949lf},
{0.103018020321880566lf, 0.701384982021666881lf, 0.358724177976299963lf, -0.393491791329968255lf, 0.077736837336741735lf, -0.003976323002163404lf},
{0.107934365393394294lf, 0.689549641630688104lf, 0.370120945647412047lf, -0.398979047014133503lf, 0.079057832596021810lf, -0.004103529667528892lf},
{0.113010396163514049lf, 0.677431706508740517lf, 0.381692601377584317lf, -0.404504080358103257lf, 0.080376838744166984lf, -0.004229486358005868lf},
{0.118247352212620505lf, 0.665032912496849704lf, 0.393434610778555016lf, -0.410064119881731692lf, 0.081693232489146117lf, -0.004354154705966241lf},
{0.123646251457948608lf, 0.652355473245946671lf, 0.405342102172394081lf, -0.415656303851949849lf, 0.083006384672523997lf, -0.004477496736223533lf},
{0.129207875822307194lf, 0.639402098057201940lf, 0.417409860939419008lf, -0.421277680584927761lf, 0.084315660530612596lf, -0.004599474877600485lf},
{0.134932756559547951lf, 0.626176009796040489lf, 0.429632324025926327lf, -0.426925208809898094lf, 0.085620419959337835lf, -0.004720051974373607lf},
{0.140821159242302762lf, 0.612680962863626277lf, 0.442003574618920370lf, -0.432595758094972138lf, 0.086920017782719461lf, -0.004839191297591166lf},
{0.146873068418083674lf, 0.598921261209221845lf, 0.454517336994991417lf, -0.438286109335248641lf, 0.088213804024860093lf, -0.004956856556261178lf},
{0.153088171940439555lf, 0.584901776366409498lf, 0.467166971550447729lf, -0.443992955303478487lf, 0.089501124185337164lf, -0.005073011908406005lf},
{0.159465844982420890lf, 0.570627965495801526lf, 0.479945470019780718lf, -0.449712901263520481lf, 0.090781319517890660lf, -0.005187621971980164lf},
{0.166005133740237287lf, 0.556105889416457222lf, 0.492845450889479064lf, -0.455442465646785144lf, 0.092053727312297495lf, -0.005300651835648033lf},
{0.172704738835556704lf, 0.541342230607878783lf, 0.505859155014169226lf, -0.461178080791833422lf, 0.093317681179321793lf, -0.005412067069418198lf},
{0.179562998425537801lf, 0.526344311164082868lf, 0.518978441441994121lf, -0.466916093747262118lf, 0.094572511338629164lf, -0.005521833735131145lf},
{0.186577871030267461lf, 0.511120110680904904lf, 0.532194783456081733lf, -0.472652767137972107lf, 0.095817544909551328lf, -0.005629918396797170lf},
{0.193746918087925657lf, 0.495678284057337715lf, 0.545499264838888331lf, -0.478384280094883152lf, 0.097052106204585972lf, -0.005736288130781283lf},
{0.201067286248598487lf, 0.480028179191400506lf, 0.558882576366125483lf, -0.484106729248125311lf, 0.098275517025515763lf, -0.005840910535832091lf},
{0.208535689418296144lf, 0.464179854550690330lf, 0.572335012536908883lf, -0.489816129783697429lf, 0.099487096962028468lf, -0.005943753742951513lf},
{0.216148390565362503lf, 0.448144096597491215lf, 0.585846468546668664lf, -0.495508416563555654lf, 0.100686163692719363lf, -0.006044786425102396lf},
{0.223901183302098516lf, 0.431932437047984674lf, 0.599406437509290346lf, -0.501179445309053007lf, 0.101872033288355826lf, -0.006143977806751034lf},
{0.231789373255045561lf, 0.415557169944867244lf, 0.613004007934847994lf, -0.506824993847618366lf, 0.103044020517282259lf, -0.006241297673241684lf},
{0.239807759238030771lf, 0.399031368522377416lf, 0.626627861469194580lf, -0.512440763422532863lf, 0.104201439152843287lf, -0.006336716380000258lf},
{0.247950614242683498lf, 0.382368901842496944lf, 0.640266270901580614lf, -0.518022380065615629lf, 0.105343602282700927lf, -0.006430204861564333lf},
{0.256211666261806581lf, 0.365584451180838599lf, 0.653907098446344648lf, -0.523565396032605213lf, 0.106469822619921509lf, -0.006521734640436783lf},
{0.264584078961601188lf, 0.348693526140521737lf, 0.667537794304618681lf, -0.529065291300983676lf, 0.107579412815706210lf, -0.006611277835760293lf},
{0.273060432219373705lf, 0.331712480472103888lf, 0.681145395511868257lf, -0.534517475129953956lf, 0.108671685773638629lf, -0.006698807171810145lf},
{0.281632702544017288lf, 0.314658527577445835lf, 0.694716525076961799lf, -0.539917287682246227lf, 0.109745954965321496lf, -0.006784295986302660lf},
{0.290292243397170191lf, 0.297549755675212468lf, 0.708237391418327089lf, -0.545260001707395192lf, 0.110801534747274430lf, -0.006867718238516798lf},
{0.299029765433585837lf, 0.280405142605530955lf, 0.721693788102637734lf, -0.550540824286091746lf, 0.111837740678962835lf, -0.006949048517226402lf},
{0.307835316679894166lf, 0.263244570251172982lf, 0.735071093891306315lf, -0.555754898635177907lf, 0.112853889841828273lf, -0.007028262048440715lf},
{0.316698262671531339lf, 0.246088838552513511lf, 0.748354273099941514lf, -0.560897305972820948lf, 0.113849301159189037lf, -0.007105334702950769lf},
{0.325607266568269216lf, 0.228959679093367452lf, 0.761527876275755577lf, -0.565963067443361445lf, 0.114823295716880006lf, -0.007180243003679382lf},
{0.334550269269340728lf, 0.211879768234719545lf, 0.774576041197776011lf, -0.570947146101302150lf, 0.115775197084498738lf, -0.007252964132832497lf},
{0.343514469549814683lf, 0.194872739773287895lf, 0.787482494204538641lf, -0.575844448953861443lf, 0.116704331637126124lf, -0.007323475938849712lf},
{0.352486304240439363lf, 0.177963197101751236lf, 0.800230551853782668lf, -0.580649829061487210lf, 0.117610028877387432lf, -0.007391756943151848lf},
{0.361451428473787750lf, 0.161176724847469810lf, 0.812803122918507537lf, -0.585358087695684537lf, 0.118491621757720739lf, -0.007457786346683542lf},
{0.370394696020109215lf, 0.144539899966451779lf, 0.825182710723560309lf, -0.589963976553483649lf, 0.119348447002718197lf, -0.007521544036248839lf},
{0.379300139736874709lf, 0.128080302269329316lf, 0.837351415826777412lf, -0.594462200027833010lf, 0.120179845431405877lf, -0.007583010590637860lf},
{0.388150952156572693lf, 0.111826524356096302lf, 0.849290939048477078lf, -0.598847417533171944lf, 0.120985162279327277lf, -0.007642167286542700lf},
{0.396929466237862183lf, 0.095808180936379994lf, 0.860982584852967081lf, -0.603114245885400746lf, 0.121763747520295493lf, -0.007698996104260723lf},
{0.405617136305739034lf, 0.080055917512067643lf, 0.872407265085493488lf, -0.607257261735433818lf, 0.122514956187678770lf, -0.007753479733183538lf},
{0.414194519206916745lf, 0.064601418399162669lf, 0.883545503067900029lf, -0.611271004055485179lf, 0.123238148695084107lf, -0.007805601577069981lf},
{0.422641255707107977lf, 0.049477414065814185lf, 0.894377438056048302lf, -0.615149976677205279lf, 0.123932691156303093lf, -0.007855345759101486lf},
{0.430936052157463223lf, 0.034717687763571869lf, 0.904882830061847221lf, -0.618888650880749736lf, 0.124597955704384936lf, -0.007902697126718327lf},
{0.439056662457850244lf, 0.020357081429032142lf, 0.915041065042556445lf, -0.622481468033835084lf, 0.125233320809700455lf, -0.007947641256235224lf},
{0.446979870345194819lf, 0.006431500833169013lf, 0.924831160459786306lf, -0.625922842279793668lf, 0.125838171596862169lf, -0.007990164457234942lf},
{0.454681472035526113lf, -0.007022080044185475lf, 0.934231771210436213lf, -0.629207163273618031lf, 0.126411900160364465lf, -0.008030253776738525lf},
{0.462136259248857595lf, -0.019965615437089190lf, 0.943221195931569056lf, -0.632328798964943539lf, 0.126953905878809337lf, -0.008067897003150897lf},
{0.469318002646428756lf, -0.032359985035637306lf, 0.951777383681018607lf, -0.635282098426894537lf, 0.127463595727581702lf, -0.008103082669980638lf},
{0.476199435710288110lf, -0.044164992069454345lf, 0.959877940995299328lf, -0.638061394729680265lf, 0.127940384589840556lf, -0.008135800059332779lf},
{0.482752239095556757lf, -0.055339362254267610lf, 0.967500139326147091lf, -0.640661007857802112lf, 0.128383695565690820lf, -0.008166039205173579lf},
{0.488947025486123898lf, -0.065840743623018283lf, 0.974620922856818339lf, -0.643075247669698147lf, 0.128792960279402124lf, -0.008193790896366288lf},
{0.494753324984868570lf, -0.075625707262681696lf, 0.981216916699006347lf, -0.645298416898624883lf, 0.129167619184540700lf, -0.008219046679476929lf},
{0.500139571069837530lf, -0.084649748977713102lf, 0.987264435471032487lf, -0.647324814193542375lf, 0.129507121866881542lf, -0.008241798861349308lf},
{0.505073087148136146lf, -0.092867291900650517lf, 0.992739492257706413lf, -0.649148737198744441lf, 0.129810927344967769lf, -0.008262040511448420lf},
{0.509520073739611945lf, -0.100231690070145374lf, 0.997617807952016378lf, -0.650764485670938586lf, 0.130078504368185854lf, -0.008279765463971562lf},
{0.513445596322596565lf, -0.106695232996243061lf, 1.001874820978577052lf, -0.652166364632464468lf, 0.130309331712224225lf, -0.008294968319726490lf},
{0.516813573874371990lf, -0.112209151232440074lf, 1.005485697398495581lf, -0.653348687559298757lf, 0.130502898471785672lf, -0.008307644447776066lf},
{0.519586768139094435lf, -0.116723622973579327lf, 1.008425341395084773lf, -0.654305779602474713lf, 0.130658704350423038lf, -0.008317789986848892lf},
{0.521726773656238763lf, -0.120187781698261775lf, 1.010668406139599629lf, -0.655031980841516037lf, 0.130776259947368995lf, -0.008325401846515482lf},
{0.523194008582743120lf, -0.122549724873972934lf, 1.012189305035905873lf, -0.655521649568457820lf, 0.130855087041231444lf, -0.008330477708129645lf},
{0.523947706342212882lf, -0.123756523742706015lf, 1.012962223342756429lf, -0.655769165601004289lf, 0.130894718870428084lf, -0.008333016025534760lf}
};

double k = 79.5774715459476595lf; // y = floor(k*x + b)

double dsin(double x);
// =============================================

int testsLength = 17; // change simultaneously with main program (manually)

void main()
{
// TaylorDOUBLEfma
// ====================================================
uint index = gl_GlobalInvocationID.x;
if (index < testsLength)
{
debugInfo[index] = dsin(debugInfo[index]);
}
// ====================================================
}

double dsin(double x)
{
x = mod(x+PI, TAU)-PI;

double signum = +1.00000000000000000lf;
if (x < 0)
{
x = abs(x);
signum = -1.000000000000000000lf;
}

double x2 = x*x, x3 = x2*x, x4 = x2*x2, x5 = x2*x3;

double TaylorValue;
int num = int(k*x);

TaylorValue = fma(x5, DsinTaylorTable[num][5], fma(x4, DsinTaylorTable[num][4], fma(x3, DsinTaylorTable[num][3], fma(x2, DsinTaylorTable[num][2], fma(x, DsinTaylorTable[num][1], DsinTaylorTable[num][0])))));

// ^ This works correctly on AMD, but not on NVidia ^

// "precise" modificator changes nothing.
// Deletion of "fma"s changes nothing.
// Tests show that "x5 * DsinTaylorTable[num][5]" (and similar) gives incorrect (float) result.

return TaylorValue*signum;
}
``````

You might post the absolute simplest shader you can which reproduces this issue. Two reason:

1. In the process of pairing down your example, you may discover what is causing the rounding behavior you’re seeing. And if not…
2. It will be much easier for folks to try your code and to help you determine whether the rounding behavior you’re seeing is a bug in the shader or the driver.

The thing is, the shader text I posted earlier is the minimum possible to fully understand what’s going on. In fact, it’s really very simple, if you don’t look at the Taylor interval partitioning table.
In fact, I seem to have found the problem, in the meantime.
I think the issue is that when I define the input-output SSBO buffer,

``````layout (std430, binding = 0) buffer debugInfoBH {
double debugInfo[];
};
``````

the values in which are written in the format “0.123456789123456”, and not “0.123456789123456_LF”, which, as I understand it, is fundamentally important for NVidia. The AMD driver takes care of the programmer’s code and passes double values from SSBO, while NVidia thinks it can reduce double to float if the values are written without “lf”, respectively, I cannot get more accuracy at the output than that which the shader has at the input.

So I seem to have a new question - how do I get NVidia to read double type data from SSBO? Is it possible that if the answer is no way, then I need to split all my double numbers into pairs of floats?

So the AMD driver is cheating.

The GLSL specification is very clear:

When the suffix “lf” or “LF” is present, the literal has type double. Otherwise, the literal has type float.

And not `_LF`, just `LF`. So put the `LF`s in where the standard requires them and you’ll be fine.

Yes, I agree, AMD drivers do not behave logically in general. Besides the “bug” with SSBO in this case, I also know about the lack of actual int64 support, although the documents say that “ARB_…_int64” is fully supported.

Yeah, I know, I just highlighted the “lf” so it wouldn’t get lost in the mass of numbers.

So what do I do in the end? After all, I can’t assign the suffix “lf” to the SSBO input array.