GAF Corp. yesterday disclosed that it had purchased more than 5 percent of the stock in Union Carbide Corp., fueling speculation that the Wayne, N. J.-based firm was positioning itself for a possible takeover run at the chemical giant.

The announcement stunned Wall Street analysts and propelled Carbide stock upward 3 1/8 in heavy trading on the New York Stock Exchange. Carbide closed at 51 7/8, with the gains more than compensating for the nearly two-point drop Monday after the toxic chemical leak at Carbide's Institute, W. Va. plant.

"I'm flabbergasted, frankly," said Harvey B. Storch of Fahnestock & Co. "This would be like a minnow swallowing a whale. GAF is peanuts compared to Union Carbide. . . . They are obviously bigger gamblers than I am."

Perhaps best known for its film and photographic supplies (the company traces its lineage back to the first camera shop in America), GAF has abandoned those fields in recent years and retrenched in specialty chemicals and roofing materials. It earned $56.7 million last year on sales of $731.3 million, making it less than one-tenth the size of $9 billion-a-year Union Carbide.

But some analysts speculated that GAF Chairman Samuel J. Heyman, a Connecticut real estate magnate who gained control of the company two years ago, might be planning to make a run for Carbide in conjunction with other takeover artists such as T. Boone Pickens Jr. or Carl Icahn.

GAF spokesman Donald Heymann declined to say how many Carbide shares the company had bought, or for what price, until making a formal filing with the Securities and Exchange Commission. Carbide currently has about 70.4 million common shares outstanding, giving it a market valuation of $3.67 billion. With 5 percent of the stock, GAF would own at least 3.5 million shares.

Although there have been rumors for months that Carbide was a potential takeover candidate, there were no concrete moves until yesterday. At least part of the reason is the avalanche of litigation facing Carbide as a result of last December's toxic chemical leak at Bhopal, India, which killed an estimated 2,000 and injured 200,000.

Until recently, some analysts had believed Carbide was making headway in recovering from the Bhopal disaster and that the company might escape relatively unscathed if it could reach a quick settlement with the Indian government.

But last week, lawyers in the case disclosed that negotiations aimed at a settlement had broken down and there were no further meetings scheduled. Then came Sunday's gas leak at Institute, which injured more than 142 people.

The Institute incident was widely interpreted as a public relations disaster for Carbide, puncturing holes in the company's public statements that a Bhopal-type incident couldn't happen here. More significantly, some lawyers in the case said it would strengthen the hand of the Indian government and other Bhopal plaintiffs, who recently filed a motion in federal court in New York to begin early discovery in the case.

Last January, with Carbide's stock depressed because of Bhopal, an investment group including the Bass Brothers, the wealthy Texas-based investors, had acquired a 5.4 percent stake in Carbide. But the group subsequently sold off shares, reporting that it had lowered its position to 3.5 percent of the company.

One widely discussed scenario is that Heyman and other outside investors hoped to gain control of Carbide and then sell off a large portion of its assets, whose combined book values exceed Carbide's currently depressed stock price. Some analysts said Carbide may have been attempting to head off just such a threat last month when it reshuffled its top management, naming president and chief operating officer Alec Flamm as vice chairman but removing him from control over day-to-day operations.

There also was speculation that Carbide, which has been suffering from depressed earnings, might be moving to cut its worldwide work force of 98,000 and shed some of its petrochemical operations.

A Carbide spokesman at company headquarters in Danbury, Conn., declined to make any comment about yesterday's developments.